can't update and delete a record to/from access database using listview control

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi everyone,
i was working on a project and i was using access as a back-end and vb.net as front-end.
i was able to insert and view my records into/from the db by using the listview.But i couldnt update or delete a record,everytime i run the project and press the update/delete btn,i get the same exception for the two operations "No value given for one or more records".
Please if there is anyone out there who can fix my code i would appreciate that.
Thanks. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim str As String
Dim conn As OleDbConnection = GetDbConnection()
Dim cmd As OleDbCommand
assign()
Dim str1 As String = "SELECT Bridge_Number FROM Adigrat WHERE Bridge_Number=" & TextBox1.Text & ""
str = "UPDATE Adigrat SET " & _
"Bridge_Name=" & TextBox2.Text & ",District_Name=" & ComboBox1.Text & ",Section_Name=" & ComboBox2.Text & ",Road_Segment_Name=" & ComboBox3.Text & ",Bridge_Type=" & ComboBox4.Text & ",Bridge_Span=" & TextBox3.Text & ",Bridge_Condition=" & ComboBox5.Text & ",Acquisition_Year=" & TextBox5.Text & ",Evaluation_Year=" & TextBox6.Text & ",End_of_Design_Life_Year=" & TextBox4.Text & ",Bridge_Asset_value= " & TextBox7.Text & " WHERE Bridge_Number= str1;"
cmd = New OleDbCommand(str, conn)
Dim obj As Object = cmd.ExecuteNonQuery
If Not (obj Is Nothing) Then
MsgBox("")
End If
conn.Close()
filllistview()
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim conn As OleDbConnection = GetDbConnection()
Dim x As Integer = MsgBox("Are you sure you want to delete this record?", MsgBoxStyle.YesNo, "Are you sure?")
If IsConnected() = True Then
If x = MsgBoxResult.Yes Then
Dim selectedItem As Integer = ListView1.SelectedIndices(0)
Dim sqlCmd As New OleDb.OleDbCommand("DELETE FROM Adigrat WHERE Bridge_Number = " & ListView1.Items(selectedItem).SubItems(0).Text, conn)
sqlCmd.ExecuteNonQuery()
MsgBox("Record Removed Successfully")
filllistview()
Else
Return

End If
myConn.Close()
They didnt really want to delete, so exit
This exits the sub

conn.Close()
filllistview()

View the full article
 
Back
Top