我有一个看起来像这样的 SQL 查询;
Dim query As String = "SELECT ID, " & Environment.NewLine & _
"month_of_sale, " & Environment.NewLine & _
"client_last_name, " & Environment.NewLine & _
"client_first_name, " & Environment.NewLine & _
"deal_number, " & Environment.NewLine & _
"stock_number, " & Environment.NewLine & _
"delivery_date, " & Environment.NewLine & _
"finance_manager, " & Environment.NewLine & _
"finance_income, " & Environment.NewLine & _
"record_entered " & Environment.NewLine & _
"FROM(dodge_records)" & Environment.NewLine & _
"WHERE month_of_sale = @month_of_sale AND client_last_name = @client_last_name" & Environment.NewLine & _
"ORDER BY client_last_name"
我试图在 SQL 查询中插入一个变量,但在调试网站时没有看到它发生。这是其余的代码,以便更有意义。
Case "Last Name"
Try
Dim query As String = "SELECT ID, " & Environment.NewLine & _
"month_of_sale, " & Environment.NewLine & _
"client_last_name, " & Environment.NewLine & _
"client_first_name, " & Environment.NewLine & _
"deal_number, " & Environment.NewLine & _
"stock_number, " & Environment.NewLine & _
"delivery_date, " & Environment.NewLine & _
"finance_manager, " & Environment.NewLine & _
"finance_income, " & Environment.NewLine & _
"record_entered " & Environment.NewLine & _
"FROM(dodge_records)" & Environment.NewLine & _
"WHERE month_of_sale = @month_of_sale" & Environment.NewLine & _
"WHERE client_last_name = @client_last_name" & Environment.NewLine & _
"ORDER BY client_last_name"
Using Connection = New MySqlConnection(connStr)
Using da = New MySqlDataAdapter(query, Connection)
da.SelectCommand.Parameters.AddWithValue("@month_of_sale", CurrentMonth)
da.SelectCommand.Parameters.AddWithValue("@client_last_name", ValueBoxText)
Dim DS As New DataSet
da.Fill(DS)
DodgeSearchGridView.DataSource = DS
DodgeSearchGridView.DataBind()
Connection.Close()
End Using
End Using
Catch ex As Exception
End Try
CurrentMonth 和 ValueBoxText 是我需要插入到 SQL 查询中的字符串。现在这不是我想要的。我没有收到错误消息或任何内容,查询没有返回任何内容,并且我已经仔细检查了数据库以确保其中存在此查询将返回的数据。任何人都可以帮我检查代码,以便我了解如何使这项工作正常进行吗?谢谢!