Showing posts with label selectquery. Show all posts
Showing posts with label selectquery. Show all posts

Tuesday, February 14, 2012

Can not Update in DataGrid - C#

Here is my code :

string connstring = System.Configuration.ConfigurationSettings.AppSettings["myconn"];
string selectquery = "Select * from nhacungcap";
protected System.Web.UI.WebControls.DataGrid DataGrid1;
string insertquery = "Insert into nhacungcap(mancc,tenncc,diachi,dienthoai) values(@.mancc1,@.tenncc1,@.diachi1,@.dienthoai1)";

string updatequery = "Update nhacungcap set mancc=@.mancc, tenncc=@.tenncc, diachi=@.diachi, dienthoai=@.dienthoai where (mancc=@.mancc)";
myconnection.Open();

SqlCommand updatecommand = new SqlCommand(updatequery,myconnection);
// sua truong mancc
updatecommand.Parameters.Add(new SqlParameter("@.mancc",SqlDbType.VarChar,10));
updatecommand.Parameters["@.mancc"].Value = DataGrid1.DataKeys[e.Item.ItemIndex];

// sua truong tenncc
updatecommand.Parameters.Add(new SqlParameter("@.tenncc",SqlDbType.NVarChar,50));
updatecommand.Parameters["@.tenncc"].Value = ((TextBox) e.Item.Cells[3].Controls[0]).Text;
// sua truong diachi
updatecommand.Parameters.Add(new SqlParameter("@.diachi",SqlDbType.NVarChar,200));
updatecommand.Parameters["@.diachi"].Value = ((TextBox) e.Item.Cells[4].Controls[0]).Text;
// sua truong dienthoai
updatecommand.Parameters.Add(new SqlParameter("@.dienthoai",SqlDbType.Char,10));
updatecommand.Parameters["@.dienthoai"].Value = ((TextBox) e.Item.Cells[5].Controls[0]).Text;
// kiem tra lenh thuc thi
int result1 = updatecommand.ExecuteNonQuery();
myconnection.Close();
// dieu kien kiem tra
if (result1 > 0 )
{
lbcheck.Text = "C?p Nh?t Thành công !";
}
// hien thi du lieu
hienthidulieu();

And my error appear, when I edit value in datagrid, I only update all value fields, without value@.mancc .Hu hu hu, I don't know what i must do with it.

help me please