error
-
string connection2 = ConfigurationManager.AppSettings["conn"]; OleDbConnection con2 = new OleDbConnection(connection2); string connectionString = ConfigurationManager.AppSettings["conn"]; if(DropDownList1.SelectedItem.ToString()=="ALL") { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate "; } else { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'"; } // wrap the connection and command in using block to avoid resource leaks. using (OleDbConnection connection = new OleDbConnection(connectionString)) using (OleDbCommand command = new OleDbCommand(query, connection)) { command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString()); command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString()); connection.Open(); // using a reader. You don't need a dataset as you are not persisting it in memory using (OleDbDataReader reader = command.ExecuteReader()) { GridView1.DataSource = reader; GridView1.DataBind(); } connection.Close(); } } its showing an error like Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\ can anyone help
-
string connection2 = ConfigurationManager.AppSettings["conn"]; OleDbConnection con2 = new OleDbConnection(connection2); string connectionString = ConfigurationManager.AppSettings["conn"]; if(DropDownList1.SelectedItem.ToString()=="ALL") { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate "; } else { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'"; } // wrap the connection and command in using block to avoid resource leaks. using (OleDbConnection connection = new OleDbConnection(connectionString)) using (OleDbCommand command = new OleDbCommand(query, connection)) { command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString()); command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString()); connection.Open(); // using a reader. You don't need a dataset as you are not persisting it in memory using (OleDbDataReader reader = command.ExecuteReader()) { GridView1.DataSource = reader; GridView1.DataBind(); } connection.Close(); } } its showing an error like Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\ can anyone help
-
string connection2 = ConfigurationManager.AppSettings["conn"]; OleDbConnection con2 = new OleDbConnection(connection2); string connectionString = ConfigurationManager.AppSettings["conn"]; if(DropDownList1.SelectedItem.ToString()=="ALL") { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate "; } else { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'"; } // wrap the connection and command in using block to avoid resource leaks. using (OleDbConnection connection = new OleDbConnection(connectionString)) using (OleDbCommand command = new OleDbCommand(query, connection)) { command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString()); command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString()); connection.Open(); // using a reader. You don't need a dataset as you are not persisting it in memory using (OleDbDataReader reader = command.ExecuteReader()) { GridView1.DataSource = reader; GridView1.DataBind(); } connection.Close(); } } its showing an error like Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\ can anyone help
Try This:
//define string query ; outside the If block
string query ;
if(DropDownList1.SelectedItem.ToString()=="ALL")
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate ";
}
else
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'";
}Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums
-
string connection2 = ConfigurationManager.AppSettings["conn"]; OleDbConnection con2 = new OleDbConnection(connection2); string connectionString = ConfigurationManager.AppSettings["conn"]; if(DropDownList1.SelectedItem.ToString()=="ALL") { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate "; } else { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'"; } // wrap the connection and command in using block to avoid resource leaks. using (OleDbConnection connection = new OleDbConnection(connectionString)) using (OleDbCommand command = new OleDbCommand(query, connection)) { command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString()); command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString()); connection.Open(); // using a reader. You don't need a dataset as you are not persisting it in memory using (OleDbDataReader reader = command.ExecuteReader()) { GridView1.DataSource = reader; GridView1.DataBind(); } connection.Close(); } } its showing an error like Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\ can anyone help
I think it's because you are declaring the string variable, query, inside the If statement, therefore it is out of scope. Declare the variable at the top with the other declarations.
-
using (OleDbCommand command = new OleDbCommand(query, connection)) in dis line
-
Try This:
//define string query ; outside the If block
string query ;
if(DropDownList1.SelectedItem.ToString()=="ALL")
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate ";
}
else
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'";
}Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums
okk...i got it.thnx
-
string connection2 = ConfigurationManager.AppSettings["conn"]; OleDbConnection con2 = new OleDbConnection(connection2); string connectionString = ConfigurationManager.AppSettings["conn"]; if(DropDownList1.SelectedItem.ToString()=="ALL") { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate "; } else { string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'"; } // wrap the connection and command in using block to avoid resource leaks. using (OleDbConnection connection = new OleDbConnection(connectionString)) using (OleDbCommand command = new OleDbCommand(query, connection)) { command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString()); command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString()); connection.Open(); // using a reader. You don't need a dataset as you are not persisting it in memory using (OleDbDataReader reader = command.ExecuteReader()) { GridView1.DataSource = reader; GridView1.DataBind(); } connection.Close(); } } its showing an error like Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\ can anyone help