sc.CommandText = "Insert into bob (xyz, abc) VALUES ( ?, ? )"; sc.Parameters.Clear(); sc.Parameters.Add("xyz", Row["xyz"]); sc.Parameters.Add("abc", Row["abc"]);... the first "?" corresponds to the first parameter, "xyz" in this case, the second "?" is the second parameter, etc.
>public void UpdateMyData(DataSet ds) >{ > // I wouldn't actually hard-code the connection string here, it should be in your config settings > string TestConnection = "server=(local);database=MyDataBase;uid=sa;pwd=MyPassword"; > >SqlCommand sc = new SqlCommand(); >sc.Connection = new SqlConnection(TestConnection); >sc.Connection.Open(); >foreach (DataRow Row in ds.Tables[0].Rows) > { > switch (Row.RowState) > { > case DataRowState.Added : > > sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )"; > // the item in quotes is basically a foxpro INSERT - SQL command > > sc.Parameters.Clear(); > > > > sc.Parameters.Add("@xyz", Row["xyz"]); > sc.Parameters.Add("@abc", Row["abc"]); > // the 2 lines above replace @xyz, @abc in the INSERT command with the actual > // contents of the row that is in focus in current iteration of the foreach > > sc.ExecuteNonQuery(); > // here the changes are committed to the table > break; > > // Do the same for DataRowState Deleted and Modified > case DataRowState.Deleted : > break; > case DataRowState.Modified : > break; > } > } > sc.Connection.Close(); >}>