update a row in datagrid

G

Guest

Actually my code looks like this....

private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.Columns[5].Visible=true;
DataGrid1.Columns[6].Visible=true;
TextBox t1=new TextBox();
TextBox t6=new TextBox();
TextBox t7=new TextBox();

t1.Text=((TextBox)e.Item.FindControl("TextBox10")).Text
t2.Text=((TextBox)e.Item.Cells[2].FindControl("TextBox8")).Text; t3.Text=((TextBox)e.Item.Cells[3].FindControl("TextBox9")).Text;



SqlConnection con=DataAccessor.CreateConnection();
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;


cmd.CommandText=@"update tblPQOrder set
ProoductID="+t1.Text+","+"Quantity="+t2.Text+","+"UnitCost="+t3.Text+"where
ItemID="+DataGrid1.DataKeys[e.Item.ItemIndex];





cmd.ExecuteReader();
DataAccessor.CloseConnection(con);
cmd.Dispose();
Rebind();

}

the new value is not entering in to the code when i debug....Is there any
error in the SQL Update Statment???
 
N

Nicholas Paldino [.NET/C# MVP]

Jijo,

It's hard to say, Without knowing the types of the columns, I can't
tell if you should be using a number or a string as the value.

Also, you should be using a parameterized statement here, and not
setting the values yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top