0

I am trying to fetch Date, Month and Year separately from date column in Access Database.

I am using following code for it.

I don't know what is the problem with this, but either it shows me error or no data is returned.

I am new to OLEDB so I don't know if it is possible or not.

Please help.

And please show me alternatives if this way is incorrect.

    conn_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\MHV\Documents\Visual Studio 2012\Projects\UTS\UTS.mdb"

    conn = New OleDbConnection(conn_string)
    conn.Open()

    Grid_string = "SELECT datepart(mm,T_Date) from Transactions"

    Grid_cmd = New OleDbCommand(Grid_string, conn)
    RW_AD = New OleDbDataAdapter(Grid_cmd)
    Grid_DS = New DataSet

    Grid_cmd.Connection = conn
    Grid_cmd.CommandText = Grid_string

    RW_AD.Fill(Grid_DS, "Transactions")

    Grid_cmd.ExecuteNonQuery() 

    DataGridView1.DataSource = Grid_DS.Tables("Transactions").DefaultView

P.S. : Connection and other things are working fine. It only shows me error when I use datepart().

1
  • The error which I keep on getting is.-> No value given for one or more required parameters. Commented Jun 29, 2014 at 4:07

4 Answers 4

1

Can you please try to making datepart interval in quotation?

Grid_string = "SELECT datepart(\"mm\",T_Date) from Transactions"
Sign up to request clarification or add additional context in comments.

Comments

1

Using ' instead of " will fix the problem:

Grid_string = "SELECT datepart('mm',T_Date) from Transactions"

Comments

0

Try using m instead of mm

Grid_string = "SELECT datepart('m',T_Date) from Transactions"

Comments

0

Data Type returned is Int16. Cast to Int16 or you'll get error

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.