Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataAdapter.InsertCommand
Message
De
23/09/2003 14:20:20
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
 
 
À
23/09/2003 13:17:46
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
00831482
Message ID:
00831619
Vues:
19
Here's my updated Insert command. The first thing I do is create a DataSet with some data, then I attempt to insert a record using the same DataSet. The code executes without any error but no records get insert.

Thanks,

Jerry
string lc_emkey = "TEST1";
string lc_emkey2 = "JERRYT";
string lc_ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\\apps\\;Mode=ReadWrite|Share Deny None";
string lc_sql = "SELECT * FROM employee where em_key = '" + lc_emkey2 + "'";

//Connection string.
OleDbConnection conn = new OleDbConnection(lc_ConnectionString);

//Create DataAdapter. Fill with some data.
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbCommand cmd = new OleDbCommand(lc_sql, conn);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "employee");

// Create the InsertCommand.
lc_sql = "INSERT INTO employee (em_key) VALUES ('" + lc_emkey + "')";
cmd = new OleDbCommand(lc_sql, conn);
da.InsertCommand = cmd;

///Attempt to update table.
da.Update(ds, "employee");
</pref>


>Jerry,
>
>You have to have data in the DataSet in order to update. Definitely your code as it is now will complain. You have a new DataSet() ... of course there is no table in it called "employee". Even if you uncomment the .Fill() command, you still will  need to make some changes to your DataSet in order for the .Update() to update anything.
>
>~~Bonnie
>
>
>>Here's my updated code to insert a record.
>>
>><pre>
>>string lc_emkey = "TEST1";
>>string lc_ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\\apps\\;Mode=ReadWrite|Share Deny None";
>>string lc_sql = "SELECT * FROM employee where em_key = '" + lc_emkey + "'";
>>
>>//Connection string.
>>OleDbConnection conn = new OleDbConnection(lc_ConnectionString);
>>
>>//Create DataAdapter.
>>OleDbDataAdapter da = new OleDbDataAdapter();
>>
>>// Create the DeleteCommand.
>>OleDbCommand cmd = new OleDbCommand(lc_sql, conn);
>>
>>da.SelectCommand = cmd;
>>
>>lc_sql = "INSERT INTO employee (em_key) VALUES ('" + lc_emkey + "')";
>>cmd = new OleDbCommand(lc_sql, conn);
>>da.InsertCommand = cmd;
>>
>>DataSet ds = new DataSet();
>>//da.Fill(ds, "employee");
>>da.Update(ds, "employee");
>>
>>
>>>Jerry,
>>>
>>>Post your new code.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Bonnie,
>>>>
>>>>Yes, the DeleteCommand and UpdateCommand do work as shown. Just the InsertCommand example does not work.
>>>>
>>>>I have not tried the Update() method before however, I just gave it a try on all three methods. I changed all the da.Fill(ds, "employee") to da.Update(ds, "employee") and ran the three methods.
>>>>
>>>>Now none of the methods work. I get an error on the da.Update() method that says 'Update unable to find TableMapping['employee'] or DataTable employee'.
>>>>
>>>>Am I missing something when I issue the da.Update()?
>>>>
>>>>Thanks,
>>>>
>>>>Jerry
>>>>
>>>>
>>>>>Jerry,
>>>>>
>>>>>Maybe I'm missing something, but I don't see where your Delete and Update would be working correctly either. Shouldn't you be doing a da.Update(ExistingDS) instead of a da.Fill(NewDS) ?
>>>>>
>>>>>~~Bonnie
>>>>>
>>>>>>I am having trouble creating an InsertCommand to insert a record into a VFP table. However, my DeleteCommand and UpdateCommand work just fine.
>>>>>>
>>>>>>Here is my insert method:
>>>>>>
>>>>>>string lc_emkey = "TEST1";
>>>>>>string lc_ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\\apps\\;Mode=ReadWrite|Share Deny None";
>>>>>>string lc_sql = "INSERT INTO employee (em_key) VALUES ('" + lc_emkey + "') ";
>>>>>>OleDbConnection conn = new OleDbConnection(lc_ConnectionString);
>>>>>>OleDbDataAdapter da = new OleDbDataAdapter();
>>>>>>OleDbCommand cmd = new OleDbCommand(lc_sql, conn);
>>>>>>da.SelectCommand = cmd;
>>>>>>da.InsertCommand = cmd;
>>>>>>DataSet ds = new DataSet();
>>>>>>da.Fill(ds, "employee");
>>>>>>
>>>>>>
>>>>>>The following is my DeleteCommand and UpdateCommand. These 2 command work just fine. However, my InsertCommand above does not work.
>>>>>>
>>>>>>///UpdateCommand
>>>>>>string lc_emkey = "JERRY";
>>>>>>string lc_depart = "IS";
>>>>>>string lc_ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\\apps\\;Mode=ReadWrite|Share Deny None";
>>>>>>string lc_sql = "UPDATE employee SET em_depart = '" + lc_depart + "' " +
>>>>>>				"WHERE em_key = '" + lc_emkey + "'";
>>>>>>OleDbConnection conn = new OleDbConnection(lc_ConnectionString);
>>>>>>OleDbDataAdapter da = new OleDbDataAdapter();
>>>>>>OleDbCommand cmd = new OleDbCommand(lc_sql, conn);
>>>>>>da.SelectCommand = cmd;
>>>>>>da.UpdateCommand = cmd;
>>>>>>DataSet ds = new DataSet();
>>>>>>da.Fill(ds, "employee");
>>>>>>
>>>>>>//DeleteCommand
>>>>>>string lc_emkey = "JERRYT";
>>>>>>string lc_ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\\apps\\;Mode=ReadWrite|Share Deny None";
>>>>>>OleDbConnection conn = new OleDbConnection(lc_ConnectionString);
>>>>>>OleDbDataAdapter da = new OleDbDataAdapter();
>>>>>>OleDbCommand cmd = new OleDbCommand("DELETE FROM employee WHERE em_key = '" + lc_emkey + "'", conn);
>>>>>>da.SelectCommand = cmd;
>>>>>>da.DeleteCommand = cmd;
>>>>>>DataSet ds = new DataSet();
>>>>>>da.Fill(ds, "employee");
>>>>>>
>>>>>>
>>>>>>What am I doing wrong?
>>>>>>
>>>>>>Thanks,
>>>>>>
>>>>>>Jerry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform