将数据转换为组合框问题 [英] bendig data into combobox problem

查看:73
本文介绍了将数据转换为组合框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..我是编程世界的初学者我正确使用数据库项目vb.net 2008和sql server 2005我希望将数据弯曲到两个不同的表格的组合框架中,一个来自table1的combox和来自表格的另一个组合框架代码只适用于一个表格数据弯曲

这里的代码请告诉它并纠正我的错误





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()

推荐答案

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();


这篇关于将数据转换为组合框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆