Hello Guys,
I am trying to update a table using the following C# code, but it is not working.
Please let me know what I am missing. Thanks.
I am trying to update a table using the following C# code, but it is not working.
Please let me know what I am missing. Thanks.
Code:
string topic1 = Topic1TextBox.Text;
int WeekID = 1;
SqlConnection conn = new SqlConnection();
DataSet ds = new DataSet();
conn.ConnectionString = "" //defined my connection string here
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * From ClassTopics", conn);
SqlCommand cmd = new SqlCommand("Update ClassTopics Set TopicName=@TopicName Where ClassNumber='1' AND WeekID=@WeekID", conn);
cmd.Parameters.Add(new SqlParameter("@TopicName", System.Data.SqlDbType.NVarChar));
cmd.Parameters["@TopicName"].SourceColumn="TopicName";
cmd.Parameters.Add(new SqlParameter("@WeekID", System.Data.SqlDbType.Int));
cmd.Parameters["@WeekID"].SourceColumn="WeekID";
da.UpdateCommand=cmd;
da.Fill(ds, "ClassTopics");
ds.Tables["ClassTopics"].Rows[2]["TopicName"]=topic1;
ds.Tables["ClassTopics"].Rows[3]["WeekID"]=weekID;
da.Update(ds, "ClassTopics");
conn.Close();
Comment