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")
 
<pre>
   mycmd.Connection = myconn
   mycmd.CommandText = &quot;SELECT * FROM SchStudents&quot;
   myconn.Open()
   Dim dr As SqlDataReader
   dr = mycmd.ExecuteReader
 
   While dr.Read
       cbostudentname.Items.Add(dr.Item(&quot;Studentname&quot;))
 
       cbostudentname.Items.Add(dr.Item(&quot;firstName&quot;))
 
   End While
 
   myconn.Close()</pre>
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 490
1 Sergey Alexandrovich Kryukov 335
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200
0 OriginalGriff 465
1 Sergey Alexandrovich Kryukov 275
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200


Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2015
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