I have a SQL Server with a roster/information. I would like to update the table with situps, pushups, and Id. I know how to insert information into a table, but having trouble with the Update part of it.
Here is my code:
SqlConnection conns = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand("UPDATE test SET SitUps = @SitUps, pushUps = @pushUps WHERE (Id = @Id)", conns);
cmd.CommandType = CommandType.Text;
Label sitL = ((Label)FormView2.FindControl("SitUpsLabel"));
Label pushL = ((Label)FormView2.FindControl("pushUpsLabel"));
Label IdL = ((Label)FormView2.FindControl("IdLabel"));
cmd.Parameters.AddWithValue("@SitUps", sitL.Text);
cmd.Parameters.AddWithValue("@pushUps", pushL.Text);
cmd.Parameters.AddWithValue("@Id", IdL.Text);
I'm getting this error
System.NullReferenceException: Object reference not set to an instance of an object.
I'm pretty sure it's the way I'm treating the Id value. Thanks in advance!!