Problem/Question with 'Select button' column

J

Jeff Petter

I'm writing a tool in asp.net to help the owner's of the existing data to purify it prior to importing into a new structure. There are far too many fields to display all of them in the datagrid, so I have created some common views, displaying somewhat different data in each. I also have a 'Select' button which I envisioned a user being able to click which would then unhide a panel control containing all of the fields so that they could more easily edit the records they wanted to. No matter how I modify the code, it continues to bomb out when it executes sqlCommand.ExecuteReader(). I've included the code below, and if anyone has any ideas, I would really appreciate them.

Thanks,

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)

{

string key = DataGrid1.DataKeys[DataGrid1.SelectedIndex].ToString();

string sqlQuery = "SELECT * FROM server WHERE" +

"server_number = @server_number";

sqlConnection1.Open();

SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection1);

sqlCommand.Parameters.Add("@server_number", key);

//sqlCommand.Parameters[@"server_number"].Value = key;

SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

if(sqlDataReader.Read())

{

txtProjectName.Text = sqlDataReader["application_project_name"].ToString();

Panel1.Visible = true;

}

sqlDataReader.Close();

sqlConnection1.Close();

}

}

}
 
S

Stevie_mac

Since you provide no error information we can only guess.
check these
* Does sqlCommand.ExecuteReader(); return anything? (use response write to figure that out)
* Does string key have a valid value? (use response write to figure that out)
* Is your SQL generating duplicate rows? - (use response write to output sqlQuery & key )
then try running the same in a Query window
* Is there a field in the results called application_project_name
* Finally - & usually the answer, Is there any NULLs in you result set??? If so, .ToString will fail.
Try this
string sqlQuery = "SELECT * FROM server WHERE" +
"server_number = @server_number AND (NOT application_project_name IS NULL)";

I'm writing a tool in asp.net to help the owner's of the existing data to purify it prior to importing into a new structure. There are far too many fields to display all of them in the datagrid, so I have created some common views, displaying somewhat different data in each. I also have a 'Select' button which I envisioned a user being able to click which would then unhide a panel control containing all of the fields so that they could more easily edit the records they wanted to. No matter how I modify the code, it continues to bomb out when it executes sqlCommand.ExecuteReader(). I've included the code below, and if anyone has any ideas, I would really appreciate them.

Thanks,

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)

{

string key = DataGrid1.DataKeys[DataGrid1.SelectedIndex].ToString();

string sqlQuery = "SELECT * FROM server WHERE" +

"server_number = @server_number";

sqlConnection1.Open();

SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection1);

sqlCommand.Parameters.Add("@server_number", key);

//sqlCommand.Parameters[@"server_number"].Value = key;

SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

if(sqlDataReader.Read())

{

txtProjectName.Text = sqlDataReader["application_project_name"].ToString();

Panel1.Visible = true;

}

sqlDataReader.Close();

sqlConnection1.Close();

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top