p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspdotnet_website_programming thread: I Cannot Add a Record


Message #1 by "Lampros Eleftherios" <lampros@c...> on Tue, 21 May 2002 23:11:41 +0300
Hello.

I use these lines:
--------------code starts here---------------------
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
SqlConnection myConnection;

protected void Page_Load(Object Src, EventArgs E)
{
myConnection = new
SqlConnection("server=localhost;database=Counter;Trusted_Connection=yes");

}

public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e)
{

int counter;
for (counter=0; counter<10; counter++)
{
String updateCmd = "UPDATE Authors SET w1 = <%counter%> where w1
=@<%counter%>";
SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@<%counter%>",
SqlDbType.NVarChar, 11));
}
}
</script>

<body>
<form runat="server">
<asp:linkbutton id="Add" OnUpdateCommand="MyDataGrid_Update" runat="server"
Text="Add" DataKeyField="w1"/>
</form>
</body>
</html>
----------------------------------------code finishes
here------------------------------------
The .aspx file is just an linkbutton. I want to hit the button and to update
the "w1" in the database.
Everytime i hit the button the value must increase "1". Is something wrong
in the for loop ?
What is the correct code?
Terry




  Return to Index