Query Builder for DATE type

1.2k views Asked by At

I'm having a problem with my query builder. I have a datagridview which I want to filter through. I want to allow search by "NAME, SURNAME, DATE". Here is my SQL QUERY

SELECT exDate, exName, exSurname FROM examines
WHERE (exDate = @Param1) AND (exName = @Param2) AND (exSurname = @Param3)

And this is my C# code where I 'call' the query

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        this.examinesTableAdapter.FillBy(this.dbSpinDataSet.examines, dateTimePicker1.Value, textBox2.Text, textBox3.Text);
    }
    catch (SystemException ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}

in VS I get 2 ERRORS saying:

"...Project1.dbSpinDataSetTableAdapters.examinesTableAdapter, string, string, string)' has some invalid arguments." "...cannot convert from 'System.Windows.Forms.DateTimePicker' to 'string'."

I understand where is the error but I don't know how to solve it. My query was written in 'query builder' in projects DataSet. I went to FILTER columns for exDate, exName and exSurname and i wrote ? (question mark). The query builder automatically transferred it into above mentioned form "= @Param1", "= @Param2" and "= @Param3".

I know I can't treat the DateTime as string but don't know what to write into FILTER column of my query builder for my code to work.

1

There are 1 answers

0
oljko On BEST ANSWER

You have to declare a string variable, and it will work!

private void button1_Click(object sender, EventArgs e)
   {
      string your_string = dateTimePicker1.Value.ToString();
      try
      {
          this.examinesTableAdapter.FillBy(this.dbSpinDataSet.examines, your_string, textBox2.Text, textBox3.Text);
      }
      catch (SystemException ex)
      {
        System.Windows.Forms.MessageBox.Show(ex.Message);
      }
    }