Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Writing to SQL table
Message
From
16/09/2004 16:03:56
 
 
To
16/09/2004 15:57:33
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00942909
Message ID:
00943091
Views:
21
Jerry,

The way the .Update() works is that it looks at your DataSet and executes the proper Insert or Update or Delete command depending on which rows in your DataSet have been modified, added or deleted. Since, in your first example, you did nothing to the DataSet, the .Update() command did nothing.

~~Bonnie


>Thanks Bonnie, I got the second example to work by adding a
>da.Update(ds, "roster");
>at the end.
>
>However, I still don't know what is wrong with the first example.
>
>Any suggestions?
>
>Thanks,
>
>Jerry
>
>
>>Jerry,
>>
>>Combine your two examples and it'll probably do the trick.
>>
>>In your first example, you have not added any data to your DataSet, consequently the .Update() will not know it has anything to Insert.
>>
>>In your second example, you've added a row to the DataTable in the DataSet, but then do nothing to send it back to the database.
>>
>>~~Bonnie
>>
>>
>>>I am trying to use MSDE on my local PC. I have upsized a VFP9 DBC that had a few tables in it. Everything upsized successfully.
>>>
>>>I can now create a .Net WinForm and query these tables and bind them to a datagrid.
>>>
>>>However, I cannot write to these tables. Below are my two attempts to add a record to a table in the SQL database. I do not recieve any errors when running these examples. They act like they work, but a record is never added to the tables.
>>>
>>>However, I can update these tables by creating a remote view in a VFP database. I just can't update these SQL tables from .Net.
>>>
>>>What am I missing?
>>>
>>>
>>>//Example 1:
>>>string lc_conn = "Integrated Security=SSPI;" +
>>>	"Initial Catalog=mydatabase;";
>>>
>>>string SelectCmd = "SELECT * FROM roster";
>>>SqlConnection myConnection = new SqlConnection(lc_conn);
>>>SqlDataAdapter da = new SqlDataAdapter();
>>>SqlCommand mycommand = new SqlCommand(SelectCmd, myConnection);
>>>da.SelectCommand = mycommand;
>>>DataSet ds = new DataSet();
>>>da.Fill(ds, "roster");
>>>string lc_sql = "INSERT INTO roster (ro_name) Values('name 1')";
>>>mycommand = new SqlCommand(lc_sql, myConnection);
>>>da.InsertCommand = mycommand;
>>>da.Update(ds, "roster");
>>>
>>>//Example 2:
>>>string lc_conn = "Integrated Security=SSPI;" +
>>>	"Initial Catalog=mydatabase;";
>>>
>>>SqlConnection myconn = new SqlConnection(lc_conn);
>>>SqlDataAdapter da = new SqlDataAdapter("select * from roster", myconn);
>>>DataSet ds = new DataSet();
>>>DataRow mydatarow;
>>>
>>>SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(da);
>>>da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
>>>da.Fill(ds, "roster");
>>>mydatarow = ds.Tables["roster"].NewRow();
>>>mydatarow["ro_name"] = "Name 1";
>>>
>>>ds.Tables["roster"].Rows.Add(mydatarow);
>>>
>>>
>>>
>>>Thanks,
>>>
>>>Jerry
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform