Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 817
  • 884
  • 39.2k

C# window form application

Nov 11 2023 1:08 PM

Hello Team, Please I have this error in my C# window form application, Kindly help. 

private void cmbRoom_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cmbRoom.SelectedIndex != -1)
            {
                ComboBox comboBox = (ComboBox)sender;
                DataRowView selectedRow = (DataRowView)comboBox.SelectedItem;

                if (selectedRow != null)
                {
                    string selectedValue = selectedRow["roomID"].ToString();
                    string sqlQuery = "SELECT rRate FROM tblRoom WHERE roomID = @selectedValue";
                    using (SqlConnection sqlConnection = new SqlConnection(con_string))
                    {
                        sqlConnection.Open();
                        using (SqlCommand cmd = new SqlCommand(sqlQuery, sqlConnection))
                        {
                            cmd.Parameters.AddWithValue("@selectedValue", selectedValue);

                            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                            {
                                DataTable dt = new DataTable();
                                da.Fill(dt);
                                if (dt.Rows.Count > 0)
                                {
                                    txtRate.Text = dt.Rows[0]["rRate"].ToString();
                                }
                            }
                        }
                    }
                }

 


Answers (8)