Insert into Database from textbox

JAM

Member
Joined
Mar 9, 2003
Messages
24
Im trying to insert studentid and student name from textbox1 and textbox2,
but when I try to insert I get this message
"No value given for one or more required parameters",
what is wrong with the isert statment?
Code:
    Dim objConn As New OleDbConnection()

        Dim objCmd As New OleDbCommand()
        
        Dim id As string = TextBox1.Text
        Dim sname As String = TextBox2.Text


        Dim sSQL As String = "INSERT INTO Student " & "(studentid, studentname)" & "VALUES (" & id & "," & sname & ")"

        Try
            objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\student.mdb"
            objConn.Open()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.Text
            objCmd.CommandText = sSQL
            objCmd.ExecuteNonQuery()

        Catch Exc As Exception

            MsgBox(Exc.Message)

        Finally

            objConn.Close()

        End Try
 
Back
Top