Customise SQL Query RRS feed

  • General discussion

  • Actually my code is like


    da As New OleDb.OleDbDataAdapter("SELECT * FROM EmpDetails WHERE department='Production'", cnn)

    Now I want customise query means I want to take column name & search kewords through textbox,
    If I am getting variables through Textbox it will give me String in "Column Name" but after WHERE I require variable in single quote 'Search Keyword' , So how can I conver "String Variable" in to 'String Variable'
    • Moved by Paul Zhou Monday, November 28, 2011 5:25 AM move for better support (From:Common Language Runtime)
    Sunday, November 27, 2011 6:42 AM

All replies

  • Moving this thread to ADO.NET Managed Providers forum to get better support.

    Have a nice day.

    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Monday, November 28, 2011 5:25 AM
  • Hi,

    You can use SqlParameters to pass into values to your command.


    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 2, 2011 8:12 AM
  • Best to use parameters and describe the datatype when setting up the params.

        Private Sub Demo()
    Dim da As New OleDb.OleDbDataAdapter
            da.SelectCommand = 
    New OleDb.OleDbCommand("SELECT * FROM EmpDetails WHERE department=?")
            da.SelectCommand.Parameters.Add( _
    New OleDb.OleDbParameter("Department", OleDb.OleDbType.LongVarChar))
            da.SelectCommand.Parameters(0).Value = TextBox1.Text
    End Sub


    Tuesday, December 6, 2011 3:20 PM