0
我正在創建一個顯示數據表的Windows窗體。我還希望能夠從顯示的表格中選擇一行,並在調用它的表單上顯示信息。我已連接到服務器,但似乎無法填充數據表。在WinForms中顯示數據表
Dim Students As String = "select * from dbo.[students]"
Dim Studentscmd As New SqlCommand(Students, cnn)
Dim Studentstable As New DataTable
Dim Studentadapter As New SqlDataAdapter
Dim NStudents As DataSet = New DataSet()
Studentadapter.Fill(NStudents)
Datagridview.DataGridView1.DataSource = NStudents
Datagridview.DataGridView1.Show()
你的DataAdapter和你的命令或連接之間沒有聯繫,我可以看到。基本上你定義一個新的適配器並傳遞一個空的DataSet。看看MSDN中的例子,你應該怎麼做。 – DarrenMB
FILL命令前缺少'StudentAdapter.SelectCommand = StudentsCmd' – DarrenMB