关于VB.Net DataGridView追加行问题.急,请高手看看!
PrivateSubTextBox1_TextChanged(senderAsObject,eAsEventArgs)HandlesTextBox1.TextChange...
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim SqlConnection As SqlClient.SqlConnection
Dim strConnect As String = "Data Source=127.0.0.1;Initial Catalog=ScData;User Id=sa;Password=123;"
SqlConnection = New System.Data.SqlClient.SqlConnection(strConnect)
SqlConnection.Open()
Dim DataAdapter As New SqlDataAdapter
Dim Dst As New DataSet
Dim Dt As New DataTable
Dim Sql As String = "Select 批号,物料代码,物料名称,规格型号,宽度,长度,包数,每包数量,总数量'张卷数',总长度,主计量单位'单位',主单位数量'数量',Case When 最后调拨至仓库='' Then 仓库 Else 最后调拨至仓库 End'仓库',Case When 最后调拨至仓位='' Then 仓位 Else 最后调拨至仓位 End'仓位' From 物料 Where 批号= ('" & TextBox1.Text & "')"
Dim Cmd As SqlCommand = New SqlCommand(Sql, SqlConnection)
DataAdapter.SelectCommand = Cmd
DataAdapter.Fill(Dst, "info")
Dt = Dst.Tables("info")
'DataGridView1.AutoGenerateColumns = True '自动创建列
'DataGridView1.DataSource = Dt
DataGridView1.Rows.Add() ←我想连续追加符合条件的SQL语句结果集到Datagridview控件中,该如何写?
End Sub 展开
Dim SqlConnection As SqlClient.SqlConnection
Dim strConnect As String = "Data Source=127.0.0.1;Initial Catalog=ScData;User Id=sa;Password=123;"
SqlConnection = New System.Data.SqlClient.SqlConnection(strConnect)
SqlConnection.Open()
Dim DataAdapter As New SqlDataAdapter
Dim Dst As New DataSet
Dim Dt As New DataTable
Dim Sql As String = "Select 批号,物料代码,物料名称,规格型号,宽度,长度,包数,每包数量,总数量'张卷数',总长度,主计量单位'单位',主单位数量'数量',Case When 最后调拨至仓库='' Then 仓库 Else 最后调拨至仓库 End'仓库',Case When 最后调拨至仓位='' Then 仓位 Else 最后调拨至仓位 End'仓位' From 物料 Where 批号= ('" & TextBox1.Text & "')"
Dim Cmd As SqlCommand = New SqlCommand(Sql, SqlConnection)
DataAdapter.SelectCommand = Cmd
DataAdapter.Fill(Dst, "info")
Dt = Dst.Tables("info")
'DataGridView1.AutoGenerateColumns = True '自动创建列
'DataGridView1.DataSource = Dt
DataGridView1.Rows.Add() ←我想连续追加符合条件的SQL语句结果集到Datagridview控件中,该如何写?
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询