【问题标题】:Two Column Data Select SQL Server Vb.net [closed]两列数据选择 SQL Server Vb.net [关闭]
【发布时间】:2019-12-09 16:57:52
【问题描述】:

您好朋友,我需要帮助,当我通过文本框从表格中找到数据时,我需要两列(品牌型号),然后在下一行中显示该数据已经可用

Dim cmd As New SqlCommand
        cmd.Connection = cn
        cmd.CommandText = "SELECT * FROM Table_3 WHERE Brand,Model='" & TextBox5.Text & " and" & TextBox6.Text & "'"
        Dim adapter As New SqlDataAdapter(cmd)
        Dim table As New DataTable()
        adapter.Fill(table)
        If table.Rows.Count() > 0 Then
            ' TextBox_1.Text = table.Rows(0)(0).ToString()
            MessageBox.Show("this data already available")
        Else
            MessageBox.Show("not available")
        End If

【问题讨论】:

标签: sql-server vb.net


【解决方案1】:

你的 SQL 字符串错误,试试这个。

使用参数而不是连接

Dim cmd As New SqlCommand
With cmd
  .Connection = cn
  .CommandText = "SELECT * FROM Table_3 WHERE Brand = @Brand AND Model= @Model"
  .Parameters.AddWithValue("@Brand", TextBox5.Text)
  .Parameters.AddWithValue("@Model", TextBox6.Text)
End With
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() > 0 Then
  ' TextBox_1.Text = table.Rows(0)(0).ToString()
  MessageBox.Show("this data already available")
Else
  MessageBox.Show("not available")
End If

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 1970-01-01
    • 2018-03-15
    • 2023-03-18
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多