Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,797 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,312 people online right now. Registration is fast and FREE... Join Now!




OLEDB exception on .fill

 
Reply to this topicStart new topic

OLEDB exception on .fill

Paul Washburn
2 Oct, 2008 - 07:59 AM
Post #1

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 22

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
User is offlineProfile CardPM
+Quote Post

Jayman
RE: OLEDB Exception On .fill
2 Oct, 2008 - 09:04 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,955



Thanked: 43 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You are correct. One method for working around this issue is to create a global boolean variable that will be set to true until the Load event finishes. Then set the boolean to false.

Inside the SelectedIndexChanged event wrap the method call with an IF statement checking the boolean value. Fire the method only when it is false.
User is online!Profile CardPM
+Quote Post

Damage
RE: OLEDB Exception On .fill
2 Oct, 2008 - 05:31 PM
Post #3

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
when you get the error is it in green?
When i ran it in debugging it came up in green instead of yellow and if i pressed f5 again the execution would continue. and when i ran the exe the error didn't come up at all.

But if you follow jaymans workaround its a moot point tongue.gif
User is offlineProfile CardPM
+Quote Post

Paul Washburn
RE: OLEDB Exception On .fill
7 Oct, 2008 - 06:05 AM
Post #4

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 22

Yes, the error was in green, and as soon as i closed the error the program continued.

Thank you for the help and the turtorial, i have found it very useful.
User is offlineProfile CardPM
+Quote Post

Paul Washburn
RE: OLEDB Exception On .fill
7 Oct, 2008 - 07:55 AM
Post #5

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 22

I did come across one slight problem, when the form loads the information does not populate for the first record, as soon as i change the combo box the records load, any ideas as to how i could modify this so that the information for the first record loads when the form does without triggering the previously mentioned error?

below is my current code

thanks for the help

CODE

  Public blnLoadFinished As Boolean = False

    Private Sub frmModifyUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comboLoad()
        blnLoadFinished = True
    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
        If blnLoadFinished Then
            populateFields()
        End If
    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

    Private Sub comboLoad()
        '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

User is offlineProfile CardPM
+Quote Post

Jayman
RE: OLEDB Exception On .fill
7 Oct, 2008 - 08:30 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,955



Thanked: 43 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
After you have set the "blnLoadFinished = True" in the Load event, set the SelectedIndex of the ComboBox to the first record.

CODE

    Private Sub frmModifyUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comboLoad()
        blnLoadFinished = True
        cboEmployee.SelectedIndex = 0
    End Sub

User is online!Profile CardPM
+Quote Post

Paul Washburn
RE: OLEDB Exception On .fill
7 Oct, 2008 - 09:00 AM
Post #7

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 22

QUOTE(jayman9 @ 7 Oct, 2008 - 09:30 AM) *

After you have set the "blnLoadFinished = True" in the Load event, set the SelectedIndex of the ComboBox to the first record.

CODE

    Private Sub frmModifyUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comboLoad()
        blnLoadFinished = True
        cboEmployee.SelectedIndex = 0
    End Sub



Didnt seem to work, if the combo box is zero by default, would setting it to zero trigger the change event?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 01:48PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month