I was going through the VB.net/Access tutorial written by Damage, and have run accross some errors trying out the code.
When the form loads an OLEDB expection is generated with the following error:
"No value given for one or more required parameters."
Im guessing this has something to do with the way the change event fires on the combo box as it is filled?
Thanks in advance
CODE
Imports System.Data
Imports System.Data.OleDb
Public Class frmModifyUser
Private Sub frmModifyUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Used to populate the comboBox
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\My Documents\Employees.accdb")
conn.Open()
Dim myadapter As New OleDbDataAdapter("SELECT * FROM tblEmployee", conn)
Dim dtset As New DataSet
myadapter.Fill(dtset)
myadapter.Dispose()
Dim table As DataTable = dtset.Tables(0)
cboEmployee.DataSource = table
cboEmployee.DisplayMember = "EmpID"
conn.Close()
End Sub
Private Sub cboEmployee_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboEmployee.SelectedIndexChanged
'calls populatefields to setup data in the textboxes
populateFields()
End Sub
'This method is used to set the information in the textboxes according to which employee has been selected in the combobox
Private Sub populateFields()
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\My Documents\Employees.accdb")
conn.Open()
Dim userDetailsAdapter As New OleDbDataAdapter("SELECT * FROM tblEmployee where EmpID =" + cboEmployee.Text, conn)
Dim userDetailsDataSet As New DataSet
userDetailsAdapter.Fill(userDetailsDataSet)
userDetailsAdapter.Dispose()
Dim userDetailsTable As DataTable = userDetailsDataSet.Tables(0)
txtEmpID.Text = userDetailsTable.Rows(0).Item(0)
txtEmpName.Text = userDetailsTable.Rows(0).Item(1)
txtEmpPassword.Text = userDetailsTable.Rows(0).Item(2)
conn.Close()
End Sub
End Class
This post has been edited by Paul Washburn: 2 Oct, 2008 - 08:03 AM