Updating a Database

Updating a Database

Post by John » Sat, 21 Aug 2004 07:45:40


Hi

I am just learning asp.net and have hit a wall with the datagrid control. I
have populated a datagrid and am able to edit fields and retrieve the new
field values from the datagrid via the UpdateCommand event but when I try
and update the database with these new values it doesn't happen. The
database isn't updated and the datagrid doesnt change.

I fill the datagrid:

SqlDataAdapter SqlDa = new SqlDataAdapter (Sql, conn);
DataSet ds = new DataSet();
SqlDa.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
dg1.DataSource = source;
dg1.DataBind();

That works fine. I have an edit column that lets you edit the data and when
i click update the update method runs fine.

the update method gets the textbox values from the datagrid then attempts to
update the datagrid/database like this:

string Sql = "UPDATE TABLE SET field1 = @DataGridValue WHERE id = xid);

SqlCommand sqlComm = new SqlCommand(sql, conn);
sqlComm.Parameters.Add("@DataGridValue, SqlDbType.NVarChar).Value =
DataGridValue;

sqlComm.Parameters.Add("@xid, SqlDbType.Int).Value = xid;

sqlComm.ExecuteNonQuery();
dg1.EditItemIndex = -1;
dg1.DataBind();

I have verified the SQL using hard coded values and I have verified that I
amretrieving the data from the datagrid correctly by writing it to a text
box on the web form, so why wont the update happen?

SOrry for the long winded post but I can't work this out after two days of
googling!!

John
 
 
 

1. Database updates (using SqlDataAdapter) during runtime but Database Table Does Not Update

2. Capture image of App#A's window from App#B

How can I capture (an image) of the contents of Application #A window ...
from Application #B. Let's say there are two, totally separate, independent
applications running, #A & #B. From Application #B, I want to locate
Application #A, then locate #A's currently active desktop window and capture
an image of whatever's being shown.

Application #A - I have no idea what programming method/tools were used to
create this app

Application #B (the imager capturer) - will be written using the .NET CLR
and either C# or VB.NET in a Winforms Applications.

Any pointers or help appreciated.
--
F.V.

3. Quick A's to easy(?) Q's appreciated...

4. Summing a Range With N/A's

5. Count A's

6. how to conver #n/a's to 0

7. #n/a's

8. Count # of A's in a Cell

9. Vlookup reporting #N/A's

10. Conditional count in range w/#N?A's

11. how to hide #N/A's?

12. best way to sum a column with #N/a's?

13. CAnnot type lowercAse 'A's Anymore

14. Try Again / VLOOKUP without N/A's

15. Host would occasionally fail to resolve A's rec.Help!