Im having problems with my insertcommand using odbcadapter, it doesnt insert the information I needed.. But the selectcommand works fine, only the insertcommand that is having problems..

heres my code..

Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
        a = Trim(txtStudNo.Text)
        If Trim(txtStudNo.Text) = "" Or Trim(txtPword.Text) = "" Then
            MsgBox("Please enter data on empty box")
        ElseIf checkstr(a) <> 1 Then
            ' now we should query the records
            record.SelectCommand = New OdbcCommand("SELECT * FROM studlogin WHERE studNo='" & txtStudNo.Text & "'", data)

            ds = New DataSet
            If ds.Tables(0).Rows.Count > 0 Then
                dr = ds.Tables(0).Rows(0)
                If UCase(txtStudNo.Text) = UCase(dr("studno")) And UCase(txtPword.Text) = UCase(dr("password")) Then
                    record.InsertCommand = New OdbcCommand("INSERT INTO studrecords (studno, course, time) VALUES('" & txtStudNo.Text & "','" & dr("course") & "','" & TimeOfDay & "')", data)
                    MsgBox("Your now login")
                    MsgBox("Wrong info provided!")
                End If
                MsgBox("Register! Student Number doesnt exist")
            End If
        End If
    End Sub

does your code trigger an error or just not insert a new record. also, are you trying to insert a record or update a record?

personally, i am not a fan of your code. but that's just me, doesn't mean anything.

insert command makes a new entry into the database. i am pretty sure you cannot change command properties when a connection is open. i would try declaring an entirely new command if i were you.

also, small point of English: you want you're (you are now logged in), not your (as in ... it's your program).

This article has been dead for over six months. Start a new discussion instead.