组合框相关问题plz解决窗口窗体 [英] Combo box related problem plz solve it window Form

查看:60
本文介绍了组合框相关问题plz解决窗口窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是: -

mai combobox cmbRoomType ke选择索引每个下一个组合框cmbRoomNo mai show karwna chata hu

但错误是: - 无法转换类型的对象''System.Data.DataRowView''键入''System.String''。



my problem is:-
mai combobox cmbRoomType ke select index per next combobox cmbRoomNo mai show karwna chata hu
but error is :-Unable to cast object of type ''System.Data.DataRowView'' to type ''System.String''.

private void Reservation_Load(object sender, EventArgs e)
       {



             string strConnectionstring = @"Data Source=ACER-PC\SQLSERVER; Initial Catalog = hms ; Integrated Security= True"

           string sql3 = "Select Room_Type,Room_Type_ID From Room_Type ";
           SqlConnection con3 = new SqlConnection(connectionString);
           SqlCommand cmd3= new SqlCommand(sql3, con3);
           SqlDataAdapter ad3 = new SqlDataAdapter();
           DataSet ds3 = new DataSet();
           ad3.SelectCommand = cmd3;

           ad3.Fill(ds3, "Room_Type");
           cmbRoomType.DataSource = ds3.Tables[0];

           cmbRoomType.DisplayMember = "Room_Type";
           cmbRoomType.ValueMember = "Room_Type_ID";

       }

       private void cmbRoomType_SelectedIndexChanged(object sender, EventArgs e)
       {
           GetConnectionString getStng = new GetConnectionString();
           string connectionString = getStng.getString();

           string sql = "Select Room_Number,Room_ID,Room_Status From Room where Room_Type='" +  (String)cmbRoomType.SelectedItem + "' and Room_Status = 'Vacant' ";
           SqlConnection con = new SqlConnection(connectionString);
           SqlCommand cmd = new SqlCommand(sql, con);
           SqlDataAdapter ad = new SqlDataAdapter();
           DataSet ds = new DataSet();
           ad.SelectCommand = cmd;

           ad.Fill(ds, "Room");
           cmbRoomNo.DataSource = ds.Tables[0];
           cmbRoomNo.DisplayMember = "Room_Number";
           cmbRoomNo.ValueMember = "Room_ID";
       }

推荐答案

1)您的问题非常不清楚,请使用格式化工具使事物具有可读性检查你的拼写。 mai show karwna chata hu绝对没有意义!



2)
1) your question is very unclear, use the formatting tools to make things readable and check your spellings. "mai show karwna chata hu " means absolutely nothing!

2)
(String)cmbRoomType.SelectedItem

这很可能是您的问题,



尝试将其更改为:

that is most likely your issue,

Try changing it to:

(String)cmbRoomType.SelectedValue


这篇关于组合框相关问题plz解决窗口窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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