Q_OBJECT
上面是我的代码,用于在txtmonthlyallocation文本框中显示“IBSP Weekly Allocation”列的值。这段代码有什么问题,为什么它不起作用?感谢。
答案 0 :(得分:0)
选项使用DataReader查找内容并显示与找到的行相关联的字段
Dim searchValue As String = "BE-2349"
Using cn As New SqlClient.SqlConnection With {.ConnectionString = My.Settings.ConnectionString}
Using cmd As New SqlClient.SqlCommand With
{
.Connection = cn,
.CommandText = "SELECT ProductID, Name, ProductNumber FROM Production.Product WHERE ProductNumber = @ProductNumber"}
cmd.Parameters.AddWithValue("@ProductNumber", searchValue)
cn.Open()
Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader
reader.Read()
If reader.HasRows Then
TextBox1.Text = reader.GetSqlString(1)
End If
End Using
End Using
使用命令文本的xml文字
Dim searchValue As String = "BE-2349"
Using cn As New SqlClient.SqlConnection With {.ConnectionString = My.Settings.ConnectionString}
Using cmd As New SqlClient.SqlCommand With
{
.Connection = cn,
.CommandText =
<SQL>
SELECT
ProductID,
Name,
ProductNumber
FROM Production.Product
WHERE ProductNumber = @ProductNumber
</SQL>.Value}
cmd.Parameters.AddWithValue("@ProductNumber", searchValue)
cn.Open()
Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader
reader.Read()
If reader.HasRows Then
TextBox1.Text = reader.GetSqlString(1)
End If
End Using
End Using