2016-12-06 88 views
0

這很奇怪,我有一個網格工作,並顯示它需要什麼,兩個不是,他們都寫同樣的方式。DataGridView不顯示數據VB.NET

Private Sub Form2_Shown(sender As Object, e As EventArgs) Handles Me.Shown 
    access.ExecQuery("SELECT emotion1,emotion2,emotion3,emotion4,emotion5, " & _ 
        "situation1,situation2,situation3, " & _ 
        "physical1,physical2,physical3,physical4,physical5 " & _ 
        "FROM emotionlogdb ORDER BY id DESC;") 
    If Not String.IsNullOrEmpty(access.exception) Then 
     MsgBox(access.exception) : Exit Sub 
    End If 
    DataGridView1.DataSource = access.DBDT 

End Sub 

以及不兩個代碼:

Private Sub Form5_Shown(sender As Object, e As EventArgs) Handles Me.Shown 
    access.ExecQuery("SELECT journal FROM journalDB ORDER BY id DESC") 
    If Not String.IsNullOrEmpty(access.exception) Then 
     MsgBox(access.exception) : Exit Sub 
    End If 
    DataGridView1.DataSource = access.DBDT 
End Sub 

和:

Private Sub Form6_Shown(sender As Object, e As EventArgs) Handles MyBase.Load 
    Dim sit As Integer = Alg.sitMode 
    Dim em As Integer = Alg.emMode 

    Access.ExecQuery("SELECT EmPlusSitMemo FROM TrendsDB WHERE EmotionID1= " & em & "AND SitID1= " & sit & ";") 
    If Not String.IsNullOrEmpty(Access.exception) Then 
     MsgBox(Access.exception) : Exit Sub 
    End If 
    DataGridView1.DataSource = Access.DBDT 
End Sub 

我在做什麼錯,工程

碼?

回答

0

你需要嘗試什麼是把一個斷點以下行:

access.ExecQuery("SELECT journal FROM journalDB ORDER BY id DESC") 

Access.ExecQuery("SELECT EmPlusSitMemo FROM TrendsDB WHERE EmotionID1= " & em & "AND SitID1= " & sit & ";") 

,然後運行在調試模式下您的項目。如果您使用MS Visual Studio,則需要按F5鍵。但是您還需要將解決方案配置設置爲調試(以啓用調試符號的生成)而不是發佈。

當您在調試模式下啓動您的應用程序時,會生成必要的用戶活動(即單擊鏈接,按鈕)以到達顯示這兩個非工作空白表單的地方。如果您設法提升Form5_Shown或Form6_Shown事件,則調試器將停止在您設置的斷點處。

然後按F10(如果您使用的是Visual Stuido,請再次查看),並查看您的數據庫的SQL查詢是否無例外地執行。也許你拼錯了字段名稱或表名。