C#中DataSet怎么绑定2个值到combobox?
//编写SQLStringBuildersb=newStringBuilder();sb.AppendLine("selectRoomId,BedNum,RoomStat...
//编写SQL
StringBuilder sb = new StringBuilder();
sb.AppendLine("select RoomId,BedNum,RoomStateName,TypeName,Description");
sb.AppendLine("from Room,RoomState,RoomType");
sb.AppendLine("where Room.RoomStateId=RoomState.RoomStateId");
sb.AppendLine("and Room.RoomTypeId=RoomType.TypeId");
//执行SQL
using (SqlConnection con = new SqlConnection(conString))//连接对象
{
using (SqlDataAdapter adp = new SqlDataAdapter(sb.toString(), con))//操作对象
{
adp.Fill(ds);//数据填充
DataSet ds= new DataSet();//存放数据的容器
this.cmbRoom.DataSource = ds.ables[0];
this.cmbRoom.DisplayMember="Description" +"BedNum"; //问题就在这里。
this.cmbRoom.ValueMember ="RoomId";
}
}
有什么办法同事绑定2个值到控件呢?我还想在绑定的值中间加符号 展开
StringBuilder sb = new StringBuilder();
sb.AppendLine("select RoomId,BedNum,RoomStateName,TypeName,Description");
sb.AppendLine("from Room,RoomState,RoomType");
sb.AppendLine("where Room.RoomStateId=RoomState.RoomStateId");
sb.AppendLine("and Room.RoomTypeId=RoomType.TypeId");
//执行SQL
using (SqlConnection con = new SqlConnection(conString))//连接对象
{
using (SqlDataAdapter adp = new SqlDataAdapter(sb.toString(), con))//操作对象
{
adp.Fill(ds);//数据填充
DataSet ds= new DataSet();//存放数据的容器
this.cmbRoom.DataSource = ds.ables[0];
this.cmbRoom.DisplayMember="Description" +"BedNum"; //问题就在这里。
this.cmbRoom.ValueMember ="RoomId";
}
}
有什么办法同事绑定2个值到控件呢?我还想在绑定的值中间加符号 展开
1个回答
展开全部
//编写SQL
StringBuilder sb = new StringBuilder();
sb.AppendLine("select RoomId,BedNum,RoomStateName,TypeName,Description");
sb.AppendLine("from Room,RoomState,RoomType");
sb.AppendLine("where Room.RoomStateId=RoomState.RoomStateId");
sb.AppendLine("and Room.RoomTypeId=RoomType.TypeId");
//执行SQL
using (SqlConnection con = new SqlConnection(conString))//连接对象
{
using (SqlDataAdapter adp = new SqlDataAdapter(sb.toString(), con))//操作对象
{
DataSet ds= new DataSet();//存放数据的容器
adp.Fill(ds);//数据填充
for(int i = 0;i< ds.ables[0].Rows.Count;i++)
{
this.cmbRoom.Items.Add(ds.ables[0].Rows[i]["Description"].ToString());
this.cmbRoom.Items.Add(ds.ables[0].Rows[i]["BedNum"].ToString());
}
}
}
更多追问追答
追答
this.cmbRoom.Items.Add(ds.ables[0].Rows[i]["Description"].ToString()+ds.ables[0].Rows[i]["BedNum"].ToString());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询