Tuesday, February 14, 2012

Can a DataTable update an SQL Table?

Can you use a DataTable to update an SQL Table and can it be done in a batch UPDATE as opposed to incrementing through every row using a stored procedure similar to UPDATE SQLTable SET Position = @.Position WHERE ID = @.ID?

Yes.. use the dataadapter and dataset

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson05.aspx

|||

I think I found my misunderstanding with my approach. What I really should be asking is how to I access the Random001 in my DataSet in my Button1_Click event?

public DataTable GetRandLinks()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringA"].ConnectionString);
SqlCommand cmd = new SqlCommand("RandomizerSelect001", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
da.Fill(ds, "Random001");
return ds.Tables["Random001"];
}
catch
{ throw new ApplicationException("Data error"); }
}
protected void Button1_Click(object sender, EventArgs e)

{

NEED to know how to call the Random001 table so I can make changes in a loop, then write those changes up using da.Update? When I try I keep getting object not found?

}

|||

Wait a bit - I think it finally may be seeing the breaking of dawn - - - -

No comments:

Post a Comment