Hi all. I am new to asp and would like your help on a problem I am having.
I have a gridview and a button. The onclickevent of the button must place a certain value from the gridview into an int variable. The value I am trying to get from the gridview is the primarykey of the table bound to the gridview.
Here is some of my code:
string sComment = txtAddComment.Text.Trim();
int iGigId = Convert.ToInt32(GridView1.SelectedDataKey.Value);
string sConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection Connection = new SqlConnection(sConnectionString);
Connection.Open();
string sSQL = "INSERT INTO tblComments VALUES ( @uGigID , @uComment)";
SqlCommand Command1 = new SqlCommand(sSQL, Connection);
Command1.Parameters.AddWithValue("@uGigID", iGigId);
Command1.Parameters.AddWithValue("@uComment" , sComment);
Command1.ExecuteNonQuery();
Connection.Close();
The problem here is that iGigId always gets a "null" value...why?
Please help