我在VB.net中有一個帶有4個文本框的表單,用於將Customer Info插入表中。現在我想在同一個表單中將所有數據顯示到DataGridView中,單擊「showall」按鈕時會運行以下代碼。爲什麼數據沒有出現在datagridview中
dtCustomer = retrieveFull("CustomerInfo")
dgvCustomer.DataSource = dtCustomer
的retrieveFull功能如下:
Public Function retrieveFull(ByVal tblName As String) As DataTable
Try
If dsSql.Tables.Contains(tblName) Then
dsSql.Tables.Remove(tblName)
End If
cmdSql1.CommandText = "select * from " & tblName
cmdSql1.Connection = Connect()
daSql.SelectCommand = cmdSql1
daSql.Fill(dsSql, tblName)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return dsSql.Tables(tblName)
End Function
我的問題是,當我按下「SHOWALL」按鈕,這樣的數據加載到DataGridView中,所有單元都是空的。當我在單元格內單擊時,文本出現。爲什麼它是這樣的?爲什麼數據不直接顯示?請引導我。
Winforms或ASP.NET? – Steve