Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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'.

C#
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";
       }
Posted
Updated 16-Apr-13 2:56am
v2

1 solution

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)
C#
(String)cmbRoomType.SelectedItem
that is most likely your issue,

Try changing it to:
C#
(String)cmbRoomType.SelectedValue
 
Share this answer
 
Comments
[no name] 16-Apr-13 9:19am    
i will try it
and error is :-Unable to cast object of type 'System.Data.DataRowView' to type 'System.String'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900