C#读数据库数据的问题

yza3137957 2011-06-06 11:13:41
要在加载中 读2个没有任何关系的表的数据读到combobox里 怎么读?

SqlConnection conn = DBHelper.connection;
try
{
conn.Open();
string sql = "select Star.star ,bloodtype.bloodtype from star full join bloodtype on bloodtype.id =star.id ";
SqlCommand comm = new SqlCommand(sql,conn);
SqlDataReader reader = comm.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
comboBox1.Items.Add(reader["star"]);
// if (reader.HasRows)
// {
// MessageBox.Show(reader["bloodtype"].ToString());
cboBloodType.Items.Add(reader["bloodtype"]);
//}
}
}


star表中12个数据 bloodtype里4个数据 结果读完了 bloodtype内个combobox里就剩8行空格 怎么样才能一个只读4行一个只读12行
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2011-06-07
  • 打赏
  • 举报
回复
你得分别取reader啊,用一个reader读半天还是一个数据集
Change_L 2011-06-07
  • 打赏
  • 举报
回复
select * from table1,table2
风骑士之怒 2011-06-07
  • 打赏
  • 举报
回复
分两个DataReader 遍历读取

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧