S
Stijn Verrept
I have this code:
bool Found = false;
if (TextBox1.Text.Length > 0)
{
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("[GetSVZList]", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@File", SqlDbType.Int);
cmd.Parameters["@File"].Value = TextBox1.Text;
cmd.Parameters.Add("@TPID", SqlDbType.Int);
cmd.Parameters["@TPID"].Value = Session["VisitorsID"];
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows) {Found = true;}
else {
reader.Close();
SqlCommand cmd2 = new SqlCommand("[GetSVZList2]", conn);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.Add( "@SearchString", SqlDbType.VarChar, 30);
cmd2.Parameters.Add("@TPID", SqlDbType.Int);
cmd2.Parameters["@TPID"].Value = Session["VisitorsID"];
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.HasRows) {Found = true;}
}
if (!Found) {Label5.Text = "No records found!";}
else {
Panel2.Visible = true;
Panel1.Visible = false;
Label5.Text = "";
Label2.Text = "Current file: " + TextBox1.Text;
if (reader.IsClosed) {DataGrid2.DataSource = reader2;} else
{DataGrid2.DataSource = reader;}
DataGrid2.DataBind();
}
}
finally { sqlConnection1.Dispose(); }
I get the message: The name 'reader2' does not exist in the class or
namespace 'ICS.Files'. Why is this? I create it with SqlDataReader
reader2 = cmd2.ExecuteReader(); or not? What's wrong?
bool Found = false;
if (TextBox1.Text.Length > 0)
{
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("[GetSVZList]", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@File", SqlDbType.Int);
cmd.Parameters["@File"].Value = TextBox1.Text;
cmd.Parameters.Add("@TPID", SqlDbType.Int);
cmd.Parameters["@TPID"].Value = Session["VisitorsID"];
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows) {Found = true;}
else {
reader.Close();
SqlCommand cmd2 = new SqlCommand("[GetSVZList2]", conn);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.Add( "@SearchString", SqlDbType.VarChar, 30);
cmd2.Parameters.Add("@TPID", SqlDbType.Int);
cmd2.Parameters["@TPID"].Value = Session["VisitorsID"];
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.HasRows) {Found = true;}
}
if (!Found) {Label5.Text = "No records found!";}
else {
Panel2.Visible = true;
Panel1.Visible = false;
Label5.Text = "";
Label2.Text = "Current file: " + TextBox1.Text;
if (reader.IsClosed) {DataGrid2.DataSource = reader2;} else
{DataGrid2.DataSource = reader;}
DataGrid2.DataBind();
}
}
finally { sqlConnection1.Dispose(); }
I get the message: The name 'reader2' does not exist in the class or
namespace 'ICS.Files'. Why is this? I create it with SqlDataReader
reader2 = cmd2.ExecuteReader(); or not? What's wrong?