473,765 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update a row in data grid

actually my code looks like this

private void DataGrid1_Updat eCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs 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.CommandText =@"update tblPQOrder set
ProductID="+t1. Text+","+"Quant ity="+t2.Text+" ,"+"UnitCost="+ t3.Text+"where
ItemID="+DataGr id1.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,Kera la,India
Nov 16 '05 #1
1 1545
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

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
7674
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) TextBox temp temp=(TextBox)e.Item.Cells.Controls String str=temp.Text; str always returnt the old value of the cell (before being updated) would u plz tell me about whats wrong i m doin
4
2148
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
9
12988
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
7
10068
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works great, at least on my system. The reason I am doing this is some customers are pulling from VPN connections which are slow. This allows the list of rows in the data grid to appear a little quicker while the list which are not used as soon load in...
13
2457
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever works best) to display a dropdown menu of fields populated from table tblInvoiceData. This control also includes a textbox which the user can input a value. These two columns are side by side and not in a vertical layout. The user then clicks on...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.