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();
}
}
}
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();
}
}
}