Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Parameterized query

Hi,
I build Form1.cs,in the form I build a DataGrid witch linked to Dataset of Ms. Access database.
I built also the dataAdapter.
The SelectCommand SQL is with two parameters:
"Select * From tblX where(XDate Between ? AND ?);"
In Form1.cs I have two dateTimePickers (1,2)
I want to set the query parameters with the dateTimePickers valuesin run time.
My target to display only the records their date between the dataTmePickers.

The code is:
this.dateDataSet1.Clear();
//The code to set the dataAdapter query parameters
this.oleDbDataAdapter1.Fill(dateDataSet1); // with th eproper parameters

Please help...
Regards...

Comments

  • cpravincpravin Member Posts: 21
    : Hi,
    : I build Form1.cs,in the form I build a DataGrid witch linked to Dataset of Ms. Access database.
    : I built also the dataAdapter.
    : The SelectCommand SQL is with two parameters:
    : "Select * From tblX where(XDate Between ? AND ?);"
    : In Form1.cs I have two dateTimePickers (1,2)
    : I want to set the query parameters with the dateTimePickers valuesin run time.
    : My target to display only the records their date between the dataTmePickers.
    :
    : The code is:
    : this.dateDataSet1.Clear();
    : //The code to set the dataAdapter query parameters
    : this.oleDbDataAdapter1.Fill(dateDataSet1); // with th eproper parameters
    :
    : Please help...
    : Regards...
    :


    Hi
    You should first get the date range from your user.

    afetr that you should construct the dataadapter object with the neccesary qury. you can construct the query as follows

    dim sql as string = "SELECT * FROM TableName WHERE XDate Between('" + datetimepickerobject1.value +' ,'"+datetimepickerobject2.value+"')"

    Now you can use this query for filling the dataset or dataadpter.

    good luck


Sign In or Register to comment.