im trying to a update a record in the the database.. but i got an execute no query error
heres the code:
help!!!
heres the code:
VB.NET:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim obj As New OleDb.OleDbCommand
CNN.Open()
sql = "SELECT *FROM tblStudent WHERE studno = '" & txtStudno.Text & "'"
da = New OleDb.OleDbDataAdapter(sql, CNN)
da.Fill(ds, "stud")
obj = New OleDb.OleDbCommand
If ds.Tables("stud").Rows.Count > 0 Then
sql = "UPDATE tblStudent SET studno = '" & txtStudno.Text & "', lname = '" & txtLname.Text & "', fname = '" & txtFname.Text & "', mi = '" & txtMi.Text & "', yr = '" & cbYear.Text & "', section = '" & Sections.Text & "', contactnum = '" & txtContactNo.Text & "' WHERE studno = '" & txtStudno.Text & "'"
Else
sql = "INSERT INTO tblStudent(studno,lname,fname,mi,yr,section,contactnum)VALUES('" & txtStudno.Text & "', '" & txtLname.Text & "','" & txtFname.Text & "','" & txtMi.Text & "','" & cbYear.Text & "', '" & Sections.Text & "', '" & txtContactNo.Text & "')"
End If
obj.Connection = CNN
obj.CommandType = CommandType.Text
obj.CommandText = sql
obj.ExecuteNonQuery()
CNN.Close()
MessageBox.Show("Student record successfully updated!", "SJA", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call clear()
Call fill_lstStudent()
End Sub
Last edited by a moderator: