Hi Jijo,
This is how I would write my update command:
SqlConnection cn = new SqlConnection() ;
string strCn = System.Configur ation.Configura tionSettings.Ap pSettings["ConnectionStri ng"];
string cmd = "Update tblUsers set Name = "+name+", Title = "+title+", SysAdmin = '"+sSA+"', Operations = '"+sOP+"', SupportLimit = "+slimit+",
ConsultingLimit = "+climit+" where Alias = '"+alias+"'" ;
cn.ConnectionSt ring = strCn;
myCmd = new SqlCommand(cmd, cn);
myCmd.Connectio n.Open();
myCmd.ExecuteNo nQuery();
where Boolean values like SysAdmin, Operations have single quotes around them. (it depends on your value type)
You can choose to do it a few different ways from here on. One of them is to
1) Fill a dataset with the latest information from the DB
2) Datagrid.DataSo urce = dataset
3) Datagrid.DataBi nd(); should display the changes.
Hope that helps,
Michelle Hlaing
Microsoft Support Professional
***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
--------------------
Thread-Topic: update a row in data grid
thread-index: AcTQvhDzHmaOdu9 mTPipQTskyxZklg ==
X-WBNR-Posting-Host: 202.88.237.151
From: "=?Utf-8?B?amlqbyBrdXJ 1dmlsYQ==?=" <ji******@msn.c om>
Subject: update a row in data grid
Date: Mon, 22 Nov 2004 10:07:02 -0800
Lines: 43
Message-ID: <30************ *************** *******@microso ft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.1.29
Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA01.phx.gbl!TK 2MSFTNGXA03.phx .gbl
Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:2883 56
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
actually my code looks like this
private void DataGrid1_Updat eCommand(object source,
System.Web.UI. WebControls.Dat aGridCommandEve ntArgs e)
{
DataGrid1.Colum ns[5].Visible=true;
DataGrid1.Colum ns[6].Visible=true;
TextBox t1=new TextBox();
TextBox t6=new TextBox();
TextBox t7=new TextBox();
t1.Text=((TextB ox)e.Item.FindC ontrol("TextBox 10")).Text;
t2.Text=((TextB ox)e.Item.Cells[2].FindControl("T extBox8")).Text ;
t3.Text=((TextB ox)e.Item.Cells[3].FindControl("T extBox9")).Text ;
SqlConnectionco n=DataAccessor. CreateConnectio n();
SqlCommand cmd=new SqlCommand();
cmd.Connection= con;
cmd.CommandType =CommandType.Te xt;
cmd.CommandTex t=@"update tblPQOrder set
ProductID="+t1 .Text+","+"Quan tity="+t2.Text+ ","+"UnitCost=" +t3.Text+"where
ItemID="+DataG rid1.DataKeys[e.Item.ItemInde x];
cmd.ExecuteRead er();
DataAccessor.Cl oseConnection(c on);
cmd.Dispose();
Rebind();
}
But when i am updating a new item thw value is not coming to the code...,Is
there any mistake in the SQL update statment??
--
Jijo kuruvila
trivandrum,Ker ala,India