B
Brad Baker
I'm trying to write a simple asp.net page which updates some data in a SQL
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
if (Page.IsPostBack) {
string customerid = Request.QueryString["customerid"];
// Connect to the DB Server
SqlConnection objConn = new SqlConnection("Server=server;
Database=Database; UId=Username; Pwd=Password");
objConn.Open();
// Create a SQL query
string sqlquery = "UPDATE Configuration SET staging_url=@StagingURL WHERE
customer_id=@customerid ";
//Adapter command
SqlDataAdapter configuration_info_query = new SqlDataAdapter(sqlquery,
objConn);
//assign a parameter to our adapter command
configuration_info_query.SelectCommand.Parameters.Add(new
SqlParameter("@StagingURL", SqlDbType.NVarChar, 255));
configuration_info_query.SelectCommand.Parameters.Add(new
SqlParameter("@customerid", customerid));
}
}
</script>
In case your wondering - I purposefully left out the select statement in the
code above which populates the form below to reduce the size of the post.
In the body I have the following code:
<form runat="server">
<ASP:Repeater id="configuration_info_repeater" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><b>CustomerID</b></td>
<td><asp:Label ID="CustomerID" TextMode="SingleLine" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "customer_id") %>' /> </td>
</tr>
<tr>
<td><b>Staging URL</b></td>
<td><asp:TextBox ID="StagingURL" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "staging_url") %>' TextMode="SingleLine"
Width="500" /> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
<asp:Button ID="submit" runat="server" Text="submit" />
</form>
My problem is that when I press submit the database doesn't update. I'm
surely doing something stupid and obvious wrong but I'm completely baffled
what that is. If anyone has any insights I would truely appreciate them.
Thanks in Advance,
Brad
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
if (Page.IsPostBack) {
string customerid = Request.QueryString["customerid"];
// Connect to the DB Server
SqlConnection objConn = new SqlConnection("Server=server;
Database=Database; UId=Username; Pwd=Password");
objConn.Open();
// Create a SQL query
string sqlquery = "UPDATE Configuration SET staging_url=@StagingURL WHERE
customer_id=@customerid ";
//Adapter command
SqlDataAdapter configuration_info_query = new SqlDataAdapter(sqlquery,
objConn);
//assign a parameter to our adapter command
configuration_info_query.SelectCommand.Parameters.Add(new
SqlParameter("@StagingURL", SqlDbType.NVarChar, 255));
configuration_info_query.SelectCommand.Parameters.Add(new
SqlParameter("@customerid", customerid));
}
}
</script>
In case your wondering - I purposefully left out the select statement in the
code above which populates the form below to reduce the size of the post.
In the body I have the following code:
<form runat="server">
<ASP:Repeater id="configuration_info_repeater" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><b>CustomerID</b></td>
<td><asp:Label ID="CustomerID" TextMode="SingleLine" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "customer_id") %>' /> </td>
</tr>
<tr>
<td><b>Staging URL</b></td>
<td><asp:TextBox ID="StagingURL" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "staging_url") %>' TextMode="SingleLine"
Width="500" /> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
<asp:Button ID="submit" runat="server" Text="submit" />
</form>
My problem is that when I press submit the database doesn't update. I'm
surely doing something stupid and obvious wrong but I'm completely baffled
what that is. If anyone has any insights I would truely appreciate them.
Thanks in Advance,
Brad