I have code that is designed to select four columns from a table on my sql server database then populate two of them with information from the internet and then update the database with the data from the newly populated columns. I can do all of this except the updating the database.
Current Method:
create sql connection and use select command to get data from database
use dataAdapter to fill a dataSet with the result of the select command
populate columns based on web data and save changes to dataSet
???? how do i put this data into the database from the DataSet
Loading

VulpesRank #55 · 29.2K reputationPosted Aug 31, 2011, 7:18 AM EDT
alec83 reputationPosted Aug 31, 2011, 7:28 AM EDT
here is the code
"(SELECT TOP 1 rs_web_url FROM rs_web_urls ORDER BY date_entered DESC) + rs_id "+
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 31, 2011, 7:39 AM EDT
Vulpes is correct but mention the table name also as below.
SqlDataAdapter1.Update(ds, "tablename");
Thanks
If this post helps you mark it as answer
alec83 reputationPosted Aug 31, 2011, 7:42 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 31, 2011, 7:52 AM EDT
So there's nothing further for you to do.
alec83 reputationPosted Aug 31, 2011, 8:02 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 31, 2011, 9:30 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 31, 2011, 1:09 PM EDT
http://www.c-sharpcorner.com/Search/?sKeywords=DataAdapter
returns many articles but you should find a relevant one easy enough. For example Creating a Custom Data Adapter should help, at least indirectly.
Sam HobbsRank #107 · 20.5K reputationPosted Aug 31, 2011, 2:23 PM EDT
When providing sample code, it helps very much to have a simple sample that is the minimum to re-create the problem. For example, the following updates a table using a SqlDataAdapter. This code works. I am not sure what you need to do but I hope this helps.
{
try
{
Connection.Open();
}
catch (Exception ex)
{
Console.WriteLine("Open error: {0}", ex);
return;
}
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("Select * From Table1;", Connection);
DataTable Table = new DataTable();
da.Fill(Table);
foreach (DataRow r in Table.Rows)
Console.WriteLine("{0} {1}", r.Field
//
Table.Rows[3].SetField
SqlCommand UpdateCommand = new SqlCommand("UPDATE Table1 SET Value = @Value WHERE [Key] = @Key", Connection);
// Add the parameters for the UpdateCommand.
UpdateCommand.Parameters.Add("@Key", SqlDbType.Int, 4, "Key");
UpdateCommand.Parameters.Add("@Value", SqlDbType.NChar, 10, "Value");
da.UpdateCommand = UpdateCommand;
da.Update(Table);
//
foreach (DataRow r in Table.Rows)
Console.WriteLine("{0} {1}", r.Field
Sam HobbsRank #107 · 20.5K reputationPosted Aug 31, 2011, 2:29 PM EDT
alec83 reputationPosted Sep 1, 2011, 12:30 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 1, 2011, 12:40 AM EDT
alec83 reputationPosted Sep 1, 2011, 12:48 AM EDT