Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
hi all of you .. am beginner in programming world am right nw working with database project vb.net 2008 and sql server 2005 i want bend data into combobox from two diffrent tables one combox from table1 and the other combobox from table my code is working only for one table data bend
here is the code please reveiw it and correct me what is wrong
 

Dim strSQL As String = "SELECT * FROM SchStudents"
       Dim da As New SqlDataAdapter(strSQL, myconn)
       Dim dm As New DataSet
       da.Fill(dt, "SchStudents")
 

       mycmd.Connection = myconn
       mycmd.CommandText = "SELECT * FROM SchStudents"
       myconn.Open()
       Dim dr As SqlDataReader
       dr = mycmd.ExecuteReader
 
       While dr.Read
           cbostudentname.Items.Add(dr.Item("Studentname"))
 
           cbostudentname.Items.Add(dr.Item("firstName"))
 

 
       End While
 

 
       myconn.Close()
Posted 10-May-13 21:30pm
Comments
Mohammed Hameed at 11-May-13 2:41am
   
You have to close datareader also. Check the second table whether it has data or not.
crahman clahi at 11-May-13 5:18am
   
thank you mohammed for your reply

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Dim strSQL As String = "SELECT * FROM SchStudents"
       Dim da As New SqlDataAdapter(strSQL, myconn)
       Dim dm As New DataSet
       da.Fill(dt, "SchStudents")
  cbostudentname.DataSource = dm;
            cbostudentname.DataTextField = "Name";
            cbostudentname.DataValueField = "Id";
            cbostudentname.DataBind();
  Permalink  
Comments
crahman clahi at 11-May-13 5:17am
   
thank you for your answer but.
there is an error saying that datatextfield is not member of windows.form.system.combobox
how can i fix it.?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100