【发布时间】:2023-04-02 02:20:01
【问题描述】:
我遇到了一个问题,我从数据库中选择要在网格中显示的行:因此,网格上只显示了一行,其余的没有显示。
这是我的代码:
conn()
Dim qry As String = "select SN,Product_ID,Product_Description,Quantity,Supplier_Name from materialreq where Req_No=" & TextBox1.Text & ""
cmd = New SqlCommand(qry, cn)
dr = cmd.ExecuteReader()
Dim i As Integer = 0
While dr.Read() And i = DataGridView1.Rows.Count - 1
DataGridView1.Rows(i).Cells("Column1").Value = dr("SN")
DataGridView1.Rows(i).Cells("Column2").Value = dr("Product_ID")
DataGridView1.Rows(i).Cells("Column3").Value = dr("Product_Description")
DataGridView1.Rows(i).Cells("Column4").Value = dr("Quantity")
DataGridView1.Rows(i).Cells("Column5").Value = dr("Supplier_Name")
'DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("Column3").Value = dr("Product_Description").ToString()
'DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("Column4").Value = dr("Quantity").ToString()
'DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("Column5").Value = dr("Supplier_Name").ToString()
i = i + 1
End While
cn.Close()
【问题讨论】:
-
试试
While dr.Read() And i <= DataGridView1.Rows.Count - 1
标签: vb.net sqlcommand