views:

67

answers:

2

the error i get while executing the code below in OleDb

        Try
            con.Open()
            Dim cmd As New OleDbCommand("Select * from customer", con)
            cmd.CommandText = " update customer set hr =@hr,min =@min "
            cmd.Parameters.AddWithValue("@hr", ComboBoxHr.SelectedIndex.ToString())
            cmd.Parameters.AddWithValue("@min", ComboBoxMin.SelectedIndex.ToString())
            cmd.ExecuteNonQuery()
            TwoDigit(ComboBoxHr)
            MessageBox.Show("CONRATULATIONS! ...Click the Start button to see the changes")
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

Which works fine if i remove the "min" part. What could be the reason?

+1  A: 

MIN is a keyword in SQL (it's the aggregate function for finding the minimum of a group of values). Either use a different name for your column, or enclose it in [ square brackets ] - I'm not actually sure if this will work in Access, mind...

AakashM
You folks are awesome.PROBLEM SOLVEDthanks for saving my a** again :D
Indranil Mutsuddy
+1  A: 

I believe AakashM is right. You can however use a keyword as a column name as long as you put it in [] like

Try
        con.Open()
        Dim cmd As New OleDbCommand("Select * from customer", con)
        cmd.CommandText = " update customer set hr =@hr,[min] =@min "
        cmd.Parameters.AddWithValue("@hr", ComboBoxHr.SelectedIndex.ToString())
        cmd.Parameters.AddWithValue("@min", ComboBoxMin.SelectedIndex.ToString())
        cmd.ExecuteNonQuery()
        TwoDigit(ComboBoxHr)
        MessageBox.Show("CONRATULATIONS! ...Click the Start button to see the changes")
    Catch ex As Exception
        MessageBox.Show(ex.Message.ToString())
    End Try
TooFat
You folks are awesome.PROBLEM SOLVEDthanks for saving my a** again :D
Indranil Mutsuddy