0

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

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by dnanetwork
0

Sorry this might seem brainless, but what do tou mean by "search for naming container"?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.