I use this code to update data in database table.
Can reuse same code to update a dataset?
Thanks.
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString))
{
string sql = "UPDATE tbh_Categories SET Title = @Title,
Description = @Description
WHERE CategoryID = @CategoryID";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = category.ID;
cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value = category.Title;
cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = category.Description;
cn.Open();
int ret = cmd.ExecuteNonQuery();
return (ret == 1);
}
The answer is no. But, you can use DataTable.Select to identify the rows in the DataTable that you want to update. But then you will have to modify the actual table itself “by hand”.
I must ask what you are trying to do … are you trying, for example, to cache some data using an updatable DataSet? Or are you trying to avoid extra database trips? There may be a better way to do what you are trying to do if you let us know. If you want an In Memory Database, there are lots out there.
Per comment: Check out SQLite. There are .NET Wrappers that might let you do what you want.