Sql 行计数并将每行分配给标签
请过来帮忙,我被困在这里了。Sql 行计数并将每行分配给标签,sql,vb.net,visual-studio-2010,sql-server-2008,vbscript,Sql,Vb.net,Visual Studio 2010,Sql Server 2008,Vbscript,请过来帮忙,我被困在这里了。 1.我正在尝试计算表行数。 2.在此表中,“策略类型”是名称。我将分配给“当前策略”中左角的链接标签(我将通过loop.I-e完成此操作。行乞时,每行的每个名称都将没有链接标签,将生成一个链接标签,其中的文本将为“策略类型”。 3.然后单击链接标签,说明将显示在“当前策略详细信息”中 这是我解释所有这些的设计。下面的设计是我的代码,我正试图做什么 设计。 对不起,我不能发布图片,我的声誉低于10。从下面的草图中猜一猜 |“”“”“”“”“”“”“”“”“”“”“”“
1.我正在尝试计算表行数。
2.在此表中,“策略类型”是名称。我将分配给“当前策略”中左角的链接标签(我将通过loop.I-e完成此操作。行乞时,每行的每个名称都将没有链接标签,将生成一个链接标签,其中的文本将为“策略类型”。
3.然后单击链接标签,说明将显示在“当前策略详细信息”中 这是我解释所有这些的设计。下面的设计是我的代码,我正试图做什么 设计。
对不起,我不能发布图片,我的声誉低于10。从下面的草图中猜一猜 |“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” |-现行政策----------------------------------------------------------------------------------------------------
|| Linklabel1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,| |--当前策略详细信息---------------------------------------------------------------------------------------
|链接标签2 |链接标签3 |链接标签4 |链接标签5 |链接标签6 |链接标签7 |链接标签8 |链接标签9 |\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu强 代码
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
试试看(你可能不得不玩弄if-then语句,我对vb有点生疏)
听起来很棒。。。问题在哪里?谢谢兄弟的关注。这里最糟糕的是,我尝试了同样的方法,但它给出了错误。对象引用未设置为对象的实例。在那之后我什么也做不了。我想你缺少Dim da作为新的SqlDataAdapter(“从策略中选择计数(*),con)da.Fill(dt)。我对vb.netOkey很生疏,我会这样尝试。有人请帮助我。
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