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
alecPosted Sep 1, 2011, 4:48 AM
VulpesPosted Sep 1, 2011, 4:40 AM
alecPosted Sep 1, 2011, 4:30 AM
Sam HobbsPosted Aug 31, 2011, 6:29 PM
Sam HobbsPosted Aug 31, 2011, 6:23 PM
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 HobbsPosted Aug 31, 2011, 5:09 PM
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.
VulpesPosted Aug 31, 2011, 1:30 PM
alecPosted Aug 31, 2011, 12:02 PM
VulpesPosted Aug 31, 2011, 11:52 AM
So there's nothing further for you to do.
alecPosted Aug 31, 2011, 11:42 AM
Satyapriya NayakPosted Aug 31, 2011, 11:39 AM
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
alecPosted Aug 31, 2011, 11:28 AM
here is the code
"(SELECT TOP 1 rs_web_url FROM rs_web_urls ORDER BY date_entered DESC) + rs_id "+
VulpesPosted Aug 31, 2011, 11:18 AM