put value into the database

wwfc_barmy_army

New member
Joined
Apr 18, 2008
Messages
3
Programming Experience
Beginner
Hello.

I have this code and i'm trying to put the following value into the database, but it's not working.

VB.NET:
        Dim conn = New OleDbConnection()

        'connect database 
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MainDB.mdb"
        'openconnection 
        conn.Open()

        selectedID = LoginForm1.IDbox.Text
        Label1.Text = selectedID.ToString

        'text not entered
        ' If letter.Text = "" Then
        '  MsgBox("Please enter a letter")
        ' End If

        'check for correct letter
        ' If letter.Text = "H" Or "h" Then
        Dim cmd As OleDbCommand = New OleDbCommand("UPDATE pupil SET Q1 = 1 WHERE ID=" + selectedID, conn)
        ' Else
        ' Dim cmd As OleDbCommand = New OleDbCommand("UPDATE =" & TextBox1.Text & "SET Q1 = 0", conn)
        ' End If

        conn.close()

        ' Me.Hide()
        ' Question2.show()

Where am i going wrong? Thanks.
 
Hi,

I have re-written the code to show get rid of your comments to show you how to update run a update query.

VB.NET:
  ' Get Data from login form
        Dim selectedId As String
        selectedId = LoginForm1.IDbox.Text
        Label1.Text = selectedId.ToString()
 
        ' Create connection and command object
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MainDB.mdb")
        Dim cmd As New OleDbCommand("UPDATE pupil SET Q1 = 1 WHERE ID=" + selectedId, conn)
 
        ' Open connection
        conn.Open()
 
        ' Run command to execute update statement
        cmd.ExecuteNonQuery()
 
        ' Close connection
        conn.Close()

Hope this helps

Regards

ScottyB
 

Latest posts

Back
Top