选择where语句 [英] Select where statement

查看:97
本文介绍了选择where语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将特定数据显示在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?

推荐答案

首先,@ State与 @state。



接下来,Businesscombobox.SelectedItem不会返回您的想法。它将在所选项目上调用.ToString,并且可能不会返回您想要的字符串。



帮自己一个忙,将Businesscombobox.SelectedItem移动到它自己的变量并检查调试器中的内容。

First, "@State" is not the same as "@state".

Next, Businesscombobox.SelectedItem doesn't return what you think it does. It's going to call .ToString on whatever that selected item is, and that may not return the string you want.

Do yourself a favor and move the Businesscombobox.SelectedItem into its own variable and inspect the content in the debugger.
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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆