I have done some programming with VB6 and ADO and am now getting into VB.NET and ADO.NET. I have never been taught how to do things the best way; I have learned on the fly as best I can.
I am trying to create a simple screen whereby the user enters a Supplier number. After entering the number, the system will pull up the supplier fields (name, address, etc) for editing. The user can then click Save to update the records.
I want to allow the user to tab back up to the Supplier control, enter a new supplier number and have the program repopulate the fields with that new supplier number. My problem is that when the program calls the "PopulateFields" routine the second time, I get an error related to databindings.
I am using a SQL statement to only select the supplier record that the user specified. I don't need to pull all of them across over the network to edit just one. There are thousands of supplier records and at most a user might edit 2 or 3 in one session.
All examples I see in VB books and online talk about binding to a recordset and navigating through all records. Wouldn't this cause a lot of overhead? I want to retrieve and edit one record at a time.
Attached is my code to do this. Any and all comments are welcome as I am new to this and want to go about it in the best and most efficient way. Again my problem right now is the databindings error mentioned above.
Thanks,
Chris
Private Sub txtSupplier_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSupplier.Leave
If Trim(txtSupplier.Text) <> "" Then PopulateSupplierFields()
End Sub
Private Sub PopulateSupplierFields()
Dim AdoStringSupplier as String = "Provider=Microsoft.Jet.OL
EDB.4.0;Da
ta Source = SupplierDB.mdb"
Dim SqlStr As String = "Select * FROM Suppliers " & _
"WHERE Supplier = '" & txtSupplier.Text & "';"
Dim cn As New OleDbConnection(AdoStringS
upplier)
Dim da As New OleDbDataAdapter(SqlStr, cn)
Dim ds As New DataSet
da.Fill(ds, "Suppliers")
txtSupplierName.DataBindin
gs.Add("Te
xt", ds, "Suppliers.Name")
txtSupplierAddr1.DataBindi
ngs.Add("T
ext", ds, "Suppliers.Addr1")
End Sub