Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. error

error

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdatabasevisual-studioperformance
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ankitjain1110
    wrote on last edited by
    #1

    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

    M J J 4 Replies Last reply
    0
    • A ankitjain1110

      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

      M Offline
      M Offline
      Meetu Choudhary
      wrote on last edited by
      #2

      at which line?

      Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

      A 1 Reply Last reply
      0
      • A ankitjain1110

        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

        M Offline
        M Offline
        Meetu Choudhary
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • A ankitjain1110

          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

          J Offline
          J Offline
          Jay Royall
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Meetu Choudhary

            at which line?

            Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

            A Offline
            A Offline
            ankitjain1110
            wrote on last edited by
            #5

            using (OleDbCommand command = new OleDbCommand(query, connection)) in dis line

            1 Reply Last reply
            0
            • M Meetu Choudhary

              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

              A Offline
              A Offline
              ankitjain1110
              wrote on last edited by
              #6

              okk...i got it.thnx

              1 Reply Last reply
              0
              • A ankitjain1110

                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

                J Offline
                J Offline
                J4amieC
                wrote on last edited by
                #7

                So how come you're smarty enough to use params for StartDate and EndDate but not for the doctor name?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups