0

我有多个组合框需要显示候选人的姓名,从总统到缪斯,无需按任何按钮,但我不知道该怎么做..

公共类 Frm_ElemBallot

Private Sub ComboBox7_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox7.SelectedIndexChanged

End Sub

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

End Sub

结束类

我应该如何将它连接到数据库?

4

1 回答 1

0

你应该试试这种方式

示例代码:

Try
            Dim cn As SqlConnection
            Dim strCnn As String = "Your data base connection string"
            cn = New SqlConnection(strCnn)
            cn.Open()
            Dim comm As New SqlCommand("Your sp or Command text to get the data from DB", cn)
            '' If ur using Sp then Commandtype= CommandType.StoredProcedure if  'is  Text then comm.CommandType=CommandType.Text
            comm.CommandType = CommandType.StoredProcedure
            Dim da As New SqlDataAdapter(comm)
            Dim ds As New DataSet
            da.Fill(ds)
            ListBox1.Items.Clear()
            If ds.Tables.Count > 0 And ds.Tables(0).Rows.Count > 0 Then
                ListBox1.DataSource = ds
            End If
            ''Close your connections and commands.
        Catch ex As Exception
            ''Handle error if any
        End Try
于 2013-10-12T08:49:00.703 回答