更新时间:2023-11-27 10:25:04
每当遇到错误时,总是说出它在哪一行。假设错误是你执行SQL时要检查的东西是修剪(employeenamecmbbx.Text)b $ b
确保employeenamecmbbx.Text返回您的预期。
接下来浏览所有字段你的选择(津贴,基本工资等)并确保它们都存在于employeeregistration表中并且没有拼写错误。
此外你还有一个额外的逗号BankName,AccountName,BankBranch,AccountNo,&
更改为BankName,AccountName,BankBranch,AccountNo&
i am a beginner at vb.net 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 Try con = New OleDbConnection(cs) con.Open() 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 rdr.Close() End If
Whenever you get an error always say what line it is on. Assuming the error is when you execute the SQL, things to check areTrim(employeenamecmbbx.Text)
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 " &