本文介绍了如何使用VB.NET中的访问数据库在组合框选择更改中填充winforms中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是vb.net的初学者,我正在尝试使用来自访问数据库的数据填充我的winform中的文本框,以选择组合框中的值。但这是我得到的错误。 没有给出一个或多个必需参数的值。 我尝试过: Private Sub employeenamecmbbx_SelectedIndexChanged(sender As Object,e As EventArgs)处理employeenamecmbbx.SelectedIndexChanged 尝试 con =新OleDbConnection(cs) con.Open() Dim ct As String =select allowances,basicsalary,cashbenefits,vehiclefueldriver,vehiclefuel,fuelonly,vehicleonly& 住宿装修,住宿,家具,共享住宿,婚姻责任,残疾人,& oldage,tier3贡献,lifeinsurance,childeducation,agedependency,trainingcost,ssn,NoOfDependants,nochildren,& BankName,AccountName,BankBranch,AccountNo,& 来自employeeregistration where employeename =? cmd =新OleDbCommand(ct) cmd.Connection = con cmd.Parameters.Add(New OleDbParameter(employeename,OleDbType.VarChar,30)) cmd。参数(employeename)。Value = Trim(employeenamecmbbx.Text) Console.WriteLine(sql:& cmd.CommandText) rdr = cmd.ExecuteReader() 如果rdr.Read则 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())结束如果如果不是rdr则没有那么 rdr.Close()结束如果 解决方案 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 解决方案 这篇关于如何使用VB.NET中的访问数据库在组合框选择更改中填充winforms中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 12:50