I am making a furniture rental system in VB.NET
to update a ComboBox
from a Microsoft Access
Database. This code to update the ComboBox
is not working; it only works for one item, for others it shows 'NO RECORD FOUND'.
I'm using Microsoft Access
for my databases.
Public Class Form8
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\jeeva\Desktop\VB Project\18HU5A1015.accdb")
Private Sub update_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cn.Open()
Dim cm As New OleDb.OleDbCommand("select * from customerinfo", cn)
Dim dr As OleDb.OleDbDataReader = cm.ExecuteReader
While dr.Read
ComboBox1.Items.Add(dr(0).ToString)
ComboBox2.Items.Add(dr(1).ToString)
ComboBox3.Items.Add(dr(2).ToString)
ComboBox4.Items.Add(dr(3).ToString)
End While
dr.Close()
cn.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim customername = TextBox1.Text
Dim customerid = TextBox2.Text
Dim customeraddress = TextBox3.Text
Dim customeraadharno = TextBox4.Text
Try
cn.Open()
Dim cmd As New OleDb.OleDbCommand()
cmd.CommandText = "Update customerinfo set customername='" + customername + "' where customername='" + ComboBox1.SelectedItem() + "'"
cmd.CommandText = "Update customerinfo set customerid='" + customerid + "' where customername='" + ComboBox2.SelectedItem() + "'"
cmd.CommandText = "Update customerinfo set customeraddress='" + customeraddress + "' where customername='" + ComboBox3.SelectedItem() + "'"
cmd.CommandText = "Update customerinfo set customeraadharno='" + customeraadharno + "' where customername='" + ComboBox4.SelectedItem() + "'"
cmd.Connection = cn
Dim i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Record is updated successfully")
Else
MsgBox("No record found")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cn.Close()
End Try
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
End Sub