问题描述
我正在尝试将特定数据显示在gridview中。我正在尝试使用select where语句,但它没有提供任何数据。
'填充殡仪馆组合框,这通过sql显示组合框中的数据连接
I am trying to get specific data to show up in gridview. I am trying to use a select where statement, but it is not giving any data back.
'fill funeral home comboboxes, this displays data in your combobox through an sql connection
Dim funcon As New SqlConnection("sqlconstring")
Dim sqladapt As New SqlDataAdapter
funcon.Open()
Dim command As SqlCommand = New SqlCommand("Select county from [business] where [state] = @state", funcon)
command.Parameters.AddWithValue("@State", Businesscombobox.SelectedItem)
sqladapt.SelectCommand = command
sqladapt.SelectCommand.ExecuteNonQuery()
command.CommandTimeout = False
Dim dts As New DataTable
Dim dss As New DataSet
sqladapt.Fill(dts)
DataGridView1.DataSource = dts
funcon.close
不知道为什么我无法获取数据
我尝试了什么:
我试图改变组合框中文本的选择方式。我甚至尝试使用数据表中的状态来查看直接将状态植入语句中会导致数据反馈,但仍然没有。如果我不使用where语句,它会显示我的所有数据,哪里出错?
Not sure why I cannot get data to appear
What I have tried:
I have tried to change the way the text is selected in the combobox. I even tried to use a state that is in the datatable to see it directly implanting a state into the statement would result in data feedback and still nothing. If I do not use the where statement it brings up all my data, where I am going wrong?
推荐答案
Dim selected As String = Businesscombobox.SelectedItem
command.Parameters.AddWithValue...
在AddWithValue行上放置一个断点并运行代码。当调试器在此行停止时,您可以将鼠标悬停在 selected
上,以查看您传递给Parameter对象的内容。
Put a breakpoint on the AddWithValue line and run the code. When the debugger stops on this line, you can hover the mouse over selected
to see the content that you're passing to the Parameter object.
这篇关于选择where语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!