2013-07-25 2 views
0

나는 어떤 단추도 누르지 않고 대통령의 이름부터 뮤즈까지 후보자의 이름을 표시하는 데 필요한 여러 개의 콤보 상자가 있지만 어떻게해야할지 모르겠다.vb.net을 사용하여 데이터베이스에서 레코드를 표시하는 방법

공공 클래스 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 

최종 클래스

내가 데이터베이스에 연결하는 방법

?

+0

이 (https://www.google.com/search?q=populate+combobox+vb를 [구글]을 검색하십시오. net & rlz = 1C1AFAB_enUS452US452 & oq = 채우기 + 콤보 박스 + vb & aqs = chrome.2.69i57j0l3.4232j0 & sourceid = 크롬 & ie = UTF-8 # 안전 = 끄기 & rlz = 1C1AFAB_enUS452US452 & sclient = psy-ab & q = 채우기 + 콤보 박스 + vb.net + 데이터베이스 & oq = 채우기 + 콤보 박스 + vb.net + da & gs_l = serp.1.0.0i22i30l4.5829.6496.0.7396.3.3.0.0.0.0.158.411.0j3.3.0 .... 0.0.1c.1.20.psy-ab.mN6fPsjuvDs & pbx = 1 & bav = on.2 or.r_qf & bvm = bv.49784469 % 2Cd.aWc % 2Cpv.xjs.s.en_US.MpiVkF51mp A.O & fp = 1fb426de7cf3e564 & biw = 1110 & bih = 759), *** *** 결과가 많습니다. – Dom

답변

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 
관련 문제