473,809 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

data grid fails to update!

hi,
I've tried to update my database using my datagrid but there is no
change. here is the code I'm using:

private void Update_dataGrid (object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)

{

System.Web.UI.W ebControls.Text Box cstaff=new
System.Web.UI.W ebControls.Text Box();

cstaff=(System. Web.UI.WebContr ols.TextBox)e.I tem.Cells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("upd ate isp_email.staff set
stafflevel=@sta fflevel where id=id",con);

myCommand.Param eters.Add(new
SqlParameter("@ stafflevel",Sql DbType.VarChar, 45));

myCommand.Param eters["@staffleve l"].Value=cstaff.T ext;
con.Open();

myCommand.Execu teNonQuery();

con.Close();

dgupdate.EditIt emIndex=-1;

BindData();

}

ould some one help me?

Dec 7 '06 #1
3 1293
OK, I've been searching for an answer to a similar problem. I am using
VB 6.0 though, so I have no idea if the solution I used, will apply/ be
helpful to you at all. I will just throw it out there in case it helps
someone...

I think the DataGrid has a property called 'DataChanged'.

If you set the property to True, then all of the update / validating
stuff should happen.

I had a problem with when I changed values in my datagrid, it didn't
propogate through to the underlying recordset unless I moved to another
record (which in effect, checks the record you were previously on, and
if changes were made, then sets the DataChanged property to true and
does whatever validating is necessary).

Basically I just made a button, that when clicked, sets
DataGrid.DataCh anged = True ... and BAM... my underlying recordset was
updated.

Hope it helps someone... :)
rcoco wrote:
hi,
I've tried to update my database using my datagrid but there is no
change. here is the code I'm using:

private void Update_dataGrid (object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)

{

System.Web.UI.W ebControls.Text Box cstaff=new
System.Web.UI.W ebControls.Text Box();

cstaff=(System. Web.UI.WebContr ols.TextBox)e.I tem.Cells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("upd ate isp_email.staff set
stafflevel=@sta fflevel where id=id",con);

myCommand.Param eters.Add(new
SqlParameter("@ stafflevel",Sql DbType.VarChar, 45));

myCommand.Param eters["@staffleve l"].Value=cstaff.T ext;
con.Open();

myCommand.Execu teNonQuery();

con.Close();

dgupdate.EditIt emIndex=-1;

BindData();

}

ould some one help me?
Dec 7 '06 #2
Hi,

Is dgupdate your datagrid?
Then you need to execute databind for it and for its datasource

e.g.
dgupdate.sqldat asource1.databi nd();
dgupdate.databi nd();

The datagrid has no knowledge that you have updated its underlying data
source. It is just a static snapshot of the data as it previously was
before you changed it.

You have to refresh the datagrid by calling its datasource databind method
and then databind the newly refreshed datasource to the datagrid to re-sync
the data being displayed.

HTH
Mark Carew

On 7 Dec 2006 04:51:19 -0800, rcoco wrote:
hi,
I've tried to update my database using my datagrid but there is no
change. here is the code I'm using:

private void Update_dataGrid (object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)

{

System.Web.UI.W ebControls.Text Box cstaff=new
System.Web.UI.W ebControls.Text Box();

cstaff=(System. Web.UI.WebContr ols.TextBox)e.I tem.Cells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("upd ate isp_email.staff set
stafflevel=@sta fflevel where id=id",con);

myCommand.Param eters.Add(new
SqlParameter("@ stafflevel",Sql DbType.VarChar, 45));

myCommand.Param eters["@staffleve l"].Value=cstaff.T ext;
con.Open();

myCommand.Execu teNonQuery();

con.Close();

dgupdate.EditIt emIndex=-1;

BindData();

}

ould some one help me?
Dec 7 '06 #3
Is dgupdate your datagrid?
Then you need to execute databind for it and for its datasource

e.g.
dgupdate.sqldat asource1.databi nd();
dgupdate.databi nd();
Sorry Mark but there is no such property as sqldatasource1 in the
DataGrid class and DataBind() is a member of DataGrid not the
DataSource property.

In the code submitted there is a statement:

BindData();

Presumably that is a function defined elsewhere which contains the
necessary commands to bind the ammended data to the grid.

Could the author show it please?

Dec 7 '06 #4

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

Similar topics

3
1968
by: pmud | last post by:
Hi, I have 4 columns in my sql database table. I added a data adapter , data set & a data grid to view this information. But the data grid is displaying those 4 columns TWICE , i.e in the data grid i see 8 columns. In case this is useful, the primary key is Serial no. which is an identity ....i.e everytime a row is added to the database, it increments by1. Also, when i configured the data adapter, it couldnt Generate the UPDATE &...
1
1552
by: jijo kuruvila | last post by:
actually my code looks like this private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.Columns.Visible=true; DataGrid1.Columns.Visible=true; TextBox t1=new TextBox(); TextBox t6=new TextBox(); TextBox t7=new TextBox();
6
6709
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
10
1490
by: KevinMGore | last post by:
The following code: Try da.Update(ds.Tables(dg1Name)) Catch ex As Exception Console.WriteLine(ex.ToString) MessageBox.Show(ex.ToString) End Try causes this error:
2
1462
by: marty | last post by:
I did some searchs, but can't find the answer to my problems. I have a editable DataGrid. I do an update of one of the rows. Postback "OnUpdateCommand" Call Oracle proc to do that actual update, which in turn creates a new row (effective dating). Call BindGrid which retrieves the rows and binds the data to the grid again.
7
10073
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...
9
4030
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New DataTable("SliceInfo") Dim tblSliceRatings As New DataTable("SliceRatings") '.... All the adding datacolumns, datarows, etc. goes here.. DatasetInit.Tables.Add(tblSliceInfo)
2
4037
by: BenCoo | last post by:
Hello, In a gridview I've a checkbox (indicating a flag that is set or not). I fill the gridview via the wizard from ADO.NET 2.0 that generates automaticly the Insert, Update and Delete commands. I've also added the button Edit to the grid that activate the Update- and cancelbuttons. When afther I set the grid in updatemode, change the value in het checkbox and click on the updatebutton I get the error: "An error occured. Cannot...
6
2948
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
9721
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
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
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...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
3
3015
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.