Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


VB
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
Comments
Mohammed Hameed 11-May-13 2:41am    
You have to close datareader also. Check the second table whether it has data or not.
crahman clahi 11-May-13 5:18am    
thank you mohammed for your reply

1 solution

VB
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();
 
Share this answer
 
Comments
crahman clahi 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900