错误:没有给出一个或多个必需参数的值。 [英] Error :No value given for one or more required parameters.
本文介绍了错误:没有给出一个或多个必需参数的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果ComboBox1.SelectedIndex = 0那么
ComboBind(文件名)
结束如果
If ComboBox1.SelectedIndex = 0 Then
ComboBind(filename)
End If
Public Sub ComboBind(ByVal strExcelFilePath As String)
Dim strin As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strExcelFilePath & ";Extended Properties=""Excel 12.0;HDR=YES"";"
Dim con As OleDbConnection = New OleDbConnection(strin)
If con.State = ConnectionState.Closed Then
con.Open()
Dim command As OleDbCommand = New OleDbCommand()
command.CommandText = "Select* from [Sheet1$] where Department=" & ComboBox1.Text
command.Connection = con
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
adapter.SelectCommand = command
Dim dt As New DataSet
'adapter.Fill(dt, "DT")
adapter.Fill(dt)
dt.Tables(0).Columns(0).ColumnName = ComboBox1.DisplayMember
DataGridView1.DataSource = dt.Tables(0)
End If
End Sub
推荐答案
其中Department =& ComboBox1.Text
command.Connection = con
Dim adapter As OleDbDataAdapter = < span class =code-keyword> New OleDbDataAdapter()
adapter.SelectCommand = command
Dim dt 作为 新 DataSet
' adapter.Fill(dt,DT)
adapter.Fill(dt)
dt.Tables( 0 )。列( 0 )。ColumnName = ComboBox1.DisplayMember
DataGridView1.DataSource = dt.Tables( 0 )
结束 如果
结束 Sub
where Department=" & ComboBox1.Text command.Connection = con Dim adapter As OleDbDataAdapter = New OleDbDataAdapter() adapter.SelectCommand = command Dim dt As New DataSet 'adapter.Fill(dt, "DT") adapter.Fill(dt) dt.Tables(0).Columns(0).ColumnName = ComboBox1.DisplayMember DataGridView1.DataSource = dt.Tables(0) End If End Sub
你的ComboBox1.Text
价值空白
&它在执行期间生成以下查询....
YourComboBox1.Text
value wasblank
& it generates the following query during execution ....
Select* from [Sheet1
其中部门=
....并且它抛出了错误 - 没有给出一个或多个必需参数的值
。
0)检查你的ComboBox1.Text获取的原因空的。
1)不要使用ComboBox1.Text,使用 SelectedValue [ ^ ] / SelectedText [ ^ ]
2)使用参数化查询避免Sql注入。查看此示例 [ ^ ]
.... and it threw the error - No value given for one or more required parameters
.
0)Check why your ComboBox1.Text getting empty.
1)Don't use ComboBox1.Text, use SelectedValue[^]/SelectedText[^]
2)Avoid Sql injection by using parameterized queries. Check this sample[^]
这篇关于错误:没有给出一个或多个必需参数的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文