2013-10-22 41 views
0

請在這裏稍微幫助一下,我被困在這裏。
1.我試圖計算表格的行數。
2.在此表中,「策略類型」是名稱。我將分配給「當前策略」左側角落中的鏈接標籤(我將通過loop.ie完成此操作。在乞討時,每個鏈接標籤的每個名稱都不會有鏈接標籤將生成哪些文本將是「策略類型」。)
3.然後通過單擊鏈接標籤,描述將出現在「當前策略詳細信息」中。行數並將每一行分配給一個標籤

這裏是我從中解釋所有這一切的設計。下面的設計是我的代碼,我正在嘗試做什麼。

設計。
對不起,我無法發佈圖片,我的聲望低於10.從下面的草圖猜測。

|「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「 「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」 「」「|
| 。 - 當前政策------------------------ || --------------------- -------------------------------------------------- ----------- |
| | Linklabel1 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || - 當前政策詳情--- ------------------------------------------------- |
| | Linklabel2 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel3 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel4 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel5 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel6 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel7 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel8 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| | Linklabel9 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, || ,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ |

代碼。

Imports System.Data.SqlClient 
Public Class New_Policy 
Dim con As SqlConnection = New SqlConnection("Data Source=CILENTEYEZ-PC\CILENTEYEZ;Initial Catalog=Keeper;Integrated Security=True") 
Dim cmd As SqlCommand 
Dim myDA As SqlDataAdapter 
Dim myDataSet As DataSet 
Dim dr As SqlDataReader 
Dim dt As DataTable 

Private Sub Add_Policy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

    cmd = New SqlCommand("Select count(*) from Policy") 
    If con.State = ConnectionState.Closed Then con.Open() 
    dt = cmd.ExecuteScalar() 

    If dt.Rows.Count > 0 Then 

     Label15.Text = dt.Rows.Count.ToString() 
    Else 
     MsgBox("There are no rows yet.") 

    End If 


    con.Close() 

End Sub 
+0

聽起來不錯...哪來的問題? – Steve

回答

0

嘗試(ü可能不得不玩的,如果再聲明我在VB有點生疏)

Imports System.Data.SqlClient 
Public Class New_Policy 
Dim con As SqlConnection = New SqlConnection("Data Source=CILENTEYEZ-PC\CILENTEYEZ;Initial Catalog=Keeper;Integrated Security=True") 
Dim cmd As SqlCommand 
Dim myDA As SqlDataAdapter 
Dim myDataSet As DataSet 
Dim dr As SqlDataReader 
Dim dt As DataTable 

Private Sub Add_Policy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

    cmd = New SqlCommand("Select count(*) from Policy") 
    If con.State = ConnectionState.Closed Then con.Open() 
    dt = cmd.ExecuteScalar() 

If dt.Rows.Count > 0 Then 

    Label1.Text=dt.Rows(0).Item(0).ToString() 
    Label2.Text=dt.Rows(1).Item(0).ToString() 
     If dt.Rows.Count > 1 Then 
     Label3.Text=dt.Rows(2).Item(0).ToString() 
     End If 
     If dt.Rows.Count > 2 Then 
     Label4.Text=dt.Rows(3).Item(0).ToString() 
     End If 
     If dt.Rows.Count > 3 Then 
     Label5.Text=dt.Rows(4).Item(0).ToString() 
     End If 
     If dt.Rows.Count > 4 Then 
     Label6.Text=dt.Rows(5).Item(0).ToString() 
     End If 
     If dt.Rows.Count > 5 Then 
     Label7.Text=dt.Rows(6).Item(0).ToString() 
     End If 

Else 
     MsgBox("There are no rows yet.") 

    End If 


    con.Close() 

End Sub 
+0

感謝兄弟的關注。這裏混亂的事情是,我嘗試了同樣的方法,但它給錯誤。 未將對象引用設置爲對象的實例。之後我無法做任何事情。 – Habib

+0

我thnk你缺少昏暗的da作爲新的SqlDataAdapter(「從策略選擇計數(*)」,CON)DA。再次填充(dt)我很生鏽vb.net – user2615302

+0

Okey我會試試這個方法。 – Habib

相關問題