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
            record.Fill(ds)
            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)
                    record.Update(ds)
                    MsgBox("Your now login")
                    cleartext()
                Else
                    MsgBox("Wrong info provided!")
                End If
            Else
                MsgBox("Register! Student Number doesnt exist")
            End If
        End If
        data.Close()
    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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.