2016-07-29 26 views
-1

我要展示我的選擇syntac到拉布勒但我的代碼沒有工作這隻能說明1 actualy數據從SQL數據是11vb.net如何顯示在拉布勒

Try 
    If IsNothing(ds.Tables("kkpsurabaya")) = False Then 
     ds.Tables("kkpsurabaya").Rows.Clear() 
    End If 

    query = "SELECT count(total_telat) FROM kkpsurabaya WHERE LATE <=30 And Late >=1" 

    da = New SqlDataAdapter(query, conn) 
    da.Fill(ds, "kkpsurabaya") 

    Label7.Text = da.Fill(ds, "kkpsurabaya") 

    da.Dispose() 
    conn.Close() 
Catch ex As Exception 
    FatalErrorOccured(ex) 
End Try 

pic1

enter image description here

+0

是否有2個字段:「LATE」和「Late」,或只是錯字? – Grace

+0

只是錯字,但在sql –

+0

工作'Label7.Text'會顯示返回的行數?如果你想在標籤中顯示sql查詢,然後使用'Label9.Text = query' – Fabio

回答

0

現在解決

conn.Open() 

    query = "SELECT count(total_telat) as total_telat FROM kkpsurabaya WHERE total_telat <=30 and total_telat >=1" 
    cmd = New SqlCommand(query, conn) 
    Try 

     RD = cmd.ExecuteReader() 
     If RD.Read() Then 
      Label7.Text = RD.GetValue(0) 
     End If 
     RD.Close() 
    Catch ex As System.Exception 
     MsgBox(ex.Message) 
    End Try 
    conn.Close() 
+0

更好但仍不是最好的。看到我的其他答案。 – jmcilhinney

1

你不應該使用數據適配器和DataTable爲此。這是爲了得到一個表格結果集。如果你想要一個值,然後使用一個命令,並致電ExecuteScalar

Dim command As New SqlCommand(query, conn) 

Label7.Text = command.ExecuteScalar().ToString() 

要了解在什麼情況下使用什麼ADO.NET對象,看看我的例子here