Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Writing to SQL table
Message
De
16/09/2004 15:57:33
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
 
 
À
16/09/2004 13:15:02
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
00942909
Message ID:
00943087
Vues:
20
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform