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. Database & SysAdmin
  3. Database
  4. Query Problem

Query Problem

Scheduled Pinned Locked Moved Database
helpdatabase
6 Posts 2 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.
  • S Offline
    S Offline
    Sadaf Naeem
    wrote on last edited by
    #1

    Hello friends, I am trying to write a query to bring records from my ACCESS database and the field type of the column included in the where clause is date/time. my query was: command = "Select * FROM tblIncomingLetters where InwardDate Between " + dateTimePicker1.Value.Date+ " AND " + dateTimePicker2.Value.Date; I am sending this query to another fucntion that will take this query as a command txt but it is constantly giving me the error of missing operator I was wondering if anyone of you can help me in resolving the issue. Looking forward for your input.

    Sadaf

    C S 2 Replies Last reply
    0
    • S Sadaf Naeem

      Hello friends, I am trying to write a query to bring records from my ACCESS database and the field type of the column included in the where clause is date/time. my query was: command = "Select * FROM tblIncomingLetters where InwardDate Between " + dateTimePicker1.Value.Date+ " AND " + dateTimePicker2.Value.Date; I am sending this query to another fucntion that will take this query as a command txt but it is constantly giving me the error of missing operator I was wondering if anyone of you can help me in resolving the issue. Looking forward for your input.

      Sadaf

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      TRy using parameterised queries, then you can be sure that your data is going to be presented in a format your source understands.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      S 2 Replies Last reply
      0
      • C Christian Graus

        TRy using parameterised queries, then you can be sure that your data is going to be presented in a format your source understands.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        S Offline
        S Offline
        Sadaf Naeem
        wrote on last edited by
        #3

        Thanks for ur co-operation but let me briefly describe what i want my query is changing based on the filters used . to accomodate this situation , i have made a function GetData() which is being called after the user clicks on the button (btnFind) and they query is decided based on the filters specified by the user which means the parameters also change . ---Function GetData()---- private void GetData(string selectCommand) { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. string currentDirectory = System.Environment.CurrentDirectory; OleDbConnection con = new OleDbConnection(); con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + currentDirectory + "\\dbLetters.mdb';Persist Security Info=False"; // Create a new data adapter based on the specified query. dataAdapter= new OleDbDataAdapter(selectCommand, con); // Create a command builder to generate SQL update, insert, and // delete commands based on selectCommand. These are used to // update the database. OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter); // Populate a new data table and bind it to the BindingSource. DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); bindingSource1.DataSource = table; // Resize the DataGridView columns to fit the newly loaded content. dataGridView1.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dataGridView1.DataSource = bindingSource1; } -------END-------- -----query specified----- string command = ""; #region Sender of the letter is specified else if (chkFrom.Checked == true && chkDate.Checked == false && chkSubject.Checked == false) { if (cmbFrom.SelectedItem.ToString() == "Others") { command = "Select * from tblIncomingLetters where From LIKE ='" + this.txtFrom.Text+ "'"; } else

        C 1 Reply Last reply
        0
        • C Christian Graus

          TRy using parameterised queries, then you can be sure that your data is going to be presented in a format your source understands.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          S Offline
          S Offline
          Sadaf Naeem
          wrote on last edited by
          #4

          there is one thing I forgot to mention which is that once the query to retrieve the data from database is decided (string command is formed) , I call the GetData function passing it the string command GetData(command); Kidnly correct me if you think this can done in other ways!

          Sadaf

          1 Reply Last reply
          0
          • S Sadaf Naeem

            Thanks for ur co-operation but let me briefly describe what i want my query is changing based on the filters used . to accomodate this situation , i have made a function GetData() which is being called after the user clicks on the button (btnFind) and they query is decided based on the filters specified by the user which means the parameters also change . ---Function GetData()---- private void GetData(string selectCommand) { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. string currentDirectory = System.Environment.CurrentDirectory; OleDbConnection con = new OleDbConnection(); con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + currentDirectory + "\\dbLetters.mdb';Persist Security Info=False"; // Create a new data adapter based on the specified query. dataAdapter= new OleDbDataAdapter(selectCommand, con); // Create a command builder to generate SQL update, insert, and // delete commands based on selectCommand. These are used to // update the database. OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter); // Populate a new data table and bind it to the BindingSource. DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); bindingSource1.DataSource = table; // Resize the DataGridView columns to fit the newly loaded content. dataGridView1.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dataGridView1.DataSource = bindingSource1; } -------END-------- -----query specified----- string command = ""; #region Sender of the letter is specified else if (chkFrom.Checked == true && chkDate.Checked == false && chkSubject.Checked == false) { if (cmbFrom.SelectedItem.ToString() == "Others") { command = "Select * from tblIncomingLetters where From LIKE ='" + this.txtFrom.Text+ "'"; } else

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            First of all, what I said stands. Use parameterised queries if you must do SQL in your presentation layer. I think it's inexcusable, but that's another discussion. Second, read this[^]. Your code is a disaster, and a malicious user can easily comprimise your database, erase it, or gain access to any data they want from it.

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            1 Reply Last reply
            0
            • S Sadaf Naeem

              Hello friends, I am trying to write a query to bring records from my ACCESS database and the field type of the column included in the where clause is date/time. my query was: command = "Select * FROM tblIncomingLetters where InwardDate Between " + dateTimePicker1.Value.Date+ " AND " + dateTimePicker2.Value.Date; I am sending this query to another fucntion that will take this query as a command txt but it is constantly giving me the error of missing operator I was wondering if anyone of you can help me in resolving the issue. Looking forward for your input.

              Sadaf

              S Offline
              S Offline
              Sadaf Naeem
              wrote on last edited by
              #6

              Thanks for ur response . I am very grateful 2 u there r 2 problems now how to create stored procedures in MS ACCESS 2007? when I searched it over GOOGLE, there was a button to create stored procedure in the CREATE beside the query design and query wizard but that option is not available in the copy I am running on my pc? secondly due to security risks some of the content is disabled which prevents me from updating the database such as password of a particular user when I run the update query but as soon as i enabled the content , it allows me to run the update query. when i close the database the settings are again disable which restrict me to update my database through application. :confused::confused::confused::confused: I hv no clue how to overcome this problem Kindly provide me with ur assistance. Thanks

              Sadaf

              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