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

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

protected void Page_Load(Object Src, EventArgs E)
myConnection = new


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
SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@<%counter%>",
SqlDbType.NVarChar, 11));

<form runat="server">
<asp:linkbutton id="Add" OnUpdateCommand="MyDataGrid_Update" runat="server"
Text="Add" DataKeyField="w1"/>
----------------------------------------code finishes
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?

  Return to Index