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"); >>>>
>>>>>>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"); >>>>>>>>>>>>
>>>>>>///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"); >>>>>>>>>>>>