Click here to Skip to main content
15,792,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am a beginner at and i am trying to fill the textboxes in my winform with the datafrom the access database on the selection of a value in the combobox. but this is the error i get.
no value given for one or more required parameters.

What I have tried:

Private Sub employeenamecmbbx_SelectedIndexChanged(sender As Object, e As EventArgs) Handles employeenamecmbbx.SelectedIndexChanged
            con = New OleDbConnection(cs)
            Dim ct As String = "select allowances,basicsalary,cashbenefits,vehiclefueldriver,vehiclefuel,fuelonly,vehicleonly," &
                    "accomodationfurnishing,accomodationonly,furnishingonly,sharedaccomodation,marriageresponsibilities,disabled," &
                    "oldage,tier3contribution,lifeinsurance,childeducation,agedependency,trainingcost,ssn,NoOfDependants,nochildren," &
                    "BankName,AccountName,BankBranch,AccountNo," &
                    "from employeeregistration where employeename = ?"
            cmd = New OleDbCommand(ct)
            cmd.Connection = con
            cmd.Parameters.Add(New OleDbParameter("employeename", OleDbType.VarChar, 30))
            cmd.Parameters("employeename").Value = Trim(employeenamecmbbx.Text)
            Console.WriteLine("sql:" & cmd.CommandText)
            rdr = cmd.ExecuteReader()

            If rdr.Read Then
                Allowances.Text = Trim(rdr.GetValue(0).ToString())
                BasicSalary.Text = Trim(rdr.GetString(1))
                CashBenefits.Text = Trim(rdr.GetValue(2).ToString())
                vfd.Text = Trim(rdr.GetValue(2).ToString())
                vf.Text = Trim(rdr.GetValue(3).ToString())
                vonl.Text = Trim(rdr.GetValue(4).ToString())
                feun.Text = Trim(rdr.GetValue(5).ToString())
                accwf.Text = Trim(rdr.GetValue(6).ToString())
                accon.Text = Trim(rdr.GetValue(7).ToString())
                furon.Text = Trim(rdr.GetValue(8).ToString())
                shracc.Text = Trim(rdr.GetValue(9).ToString())
                maresp.Text = Trim(rdr.GetValue(10).ToString())
                disbl.Text = Trim(rdr.GetValue(11).ToString())
                olda.Text = Trim(rdr.GetValue(12).ToString())
                t3c.Text = Trim(rdr.GetValue(13).ToString())
                lifins.Text = Trim(rdr.GetValue(14).ToString())
                chedu.Text = Trim(rdr.GetValue(15).ToString())
                agdep.Text = Trim(rdr.GetValue(16).ToString())
                trncst.Text = Trim(rdr.GetValue(17).ToString())
                ssno.Text = Trim(rdr.GetValue(18).ToString())
                Nodependents.Text = Trim(rdr.GetValue(19).ToString())
                NoChildren.Text = Trim(rdr.GetValue(20).ToString())
                bntnmtxbx.Text = Trim(rdr.GetValue(21).ToString())
                actntxbx.Text = Trim(rdr.GetValue(22).ToString())
                brncnamtxbx.Text = Trim(rdr.GetValue(23).ToString())
                accnmtxbx.Text = Trim(rdr.GetValue(24).ToString())
            End If
            If Not rdr Is Nothing Then
            End If
Updated 12-Jan-17 6:36am
Richard MacCutchan 12-Jan-17 9:44am    
I do not think there should be a comma between AccountNo and from in your SELECT statement. Also, it would probably be simpler just to say Select * from ....

1 solution

Whenever you get an error always say what line it is on. Assuming the error is when you execute the SQL, things to check are


make sure "employeenamecmbbx.Text" returns what you expect.

Next go through all the fields in your select (allowances, basicsalary etc) and ensure they all exist in the employeeregistration table and that there are no spelling mistakes.

Also you have an extra comma here

"BankName,AccountName,BankBranch,AccountNo," &

change that to

"BankName,AccountName,BankBranch,AccountNo " &
Share this answer
Masta Pee 12-Jan-17 12:10pm    
thank you so much .. i have checked all that but still doesnt work.
can you send me a simple sample code to look on
Masta Pee 12-Jan-17 12:18pm    
error happens on this line
rdr = cmd.ExecuteReader()
Er.Muneer Khan 17-Jan-17 6:37am    
have you defined DataReader rdr, you put rdr but where is object defination

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900