473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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.WebControls.DataGridCommandEventArgs e)

{

System.Web.UI.WebControls.TextBox cstaff=new
System.Web.UI.WebControls.TextBox();

cstaff=(System.Web.UI.WebControls.TextBox)e.Item.C ells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("update isp_email.staff set
stafflevel=@stafflevel where id=id",con);

myCommand.Parameters.Add(new
SqlParameter("@stafflevel",SqlDbType.VarChar,45));

myCommand.Parameters["@stafflevel"].Value=cstaff.Text;
con.Open();

myCommand.ExecuteNonQuery();

con.Close();

dgupdate.EditItemIndex=-1;

BindData();

}

ould some one help me?

Dec 7 '06 #1
3 1277
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.DataChanged = 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.WebControls.DataGridCommandEventArgs e)

{

System.Web.UI.WebControls.TextBox cstaff=new
System.Web.UI.WebControls.TextBox();

cstaff=(System.Web.UI.WebControls.TextBox)e.Item.C ells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("update isp_email.staff set
stafflevel=@stafflevel where id=id",con);

myCommand.Parameters.Add(new
SqlParameter("@stafflevel",SqlDbType.VarChar,45));

myCommand.Parameters["@stafflevel"].Value=cstaff.Text;
con.Open();

myCommand.ExecuteNonQuery();

con.Close();

dgupdate.EditItemIndex=-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.sqldatasource1.databind();
dgupdate.databind();

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.WebControls.DataGridCommandEventArgs e)

{

System.Web.UI.WebControls.TextBox cstaff=new
System.Web.UI.WebControls.TextBox();

cstaff=(System.Web.UI.WebControls.TextBox)e.Item.C ells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("update isp_email.staff set
stafflevel=@stafflevel where id=id",con);

myCommand.Parameters.Add(new
SqlParameter("@stafflevel",SqlDbType.VarChar,45));

myCommand.Parameters["@stafflevel"].Value=cstaff.Text;
con.Open();

myCommand.ExecuteNonQuery();

con.Close();

dgupdate.EditItemIndex=-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.sqldatasource1.databind();
dgupdate.databind();
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
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...
1
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;...
6
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
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
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...
7
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...
9
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...
2
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...
6
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)...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.