i hve reservation form

add function and add button

 public void addreserve()
                string constring = @"Data Source=.\SQLEXPRESS;Database=htm;Integrated Security=True";
                SqlConnection con = new SqlConnection(constring);
                DataTable dt = new DataTable();
                SqlCommand com = new SqlCommand("insertreserveinfo", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.Add(new SqlParameter("@Reservation_id", myreserv.Reservation_ID1));
                com.Parameters.Add(new SqlParameter("@Guest_id", myreserv.Guest_name));
                com.Parameters.Add(new SqlParameter("@Room_ID", myreserv.Room_no));
                com.Parameters.Add(new SqlParameter("@Service_ID", myreserv.Service));
                com.Parameters.Add(new SqlParameter("@No_of_days", myreserv.No_of_days));
                com.Parameters.Add(new SqlParameter("@Check_in", myreserv.Check_in));
                com.Parameters.Add(new SqlParameter("@Check_out", myreserv.Check_out));

            add button

    private void add_Click_2(object sender, EventArgs e)

                    Reservation_manager manage = new Reservation_manager(info);

                    info.Reservation_ID1 = Convert.ToInt32(txt_reser.Text);
                    Guest_info mygst = new Guest_info();
                    info.Guest_name = text_guest.SelectedValue.ToString();
                    Room myrm = new Room();
                    info.Room_no = Convert.ToInt32(txt_room.Text);
                    info.Service = txt_servce.SelectedValue.ToString();
                    info.No_of_days = Convert.ToInt32(txt_days.Text);
                    info.Check_in = Convert.ToDateTime(check_in.Text);
                    info.Check_out = Convert.ToDateTime(check_out.Text);
                    dataGridView1.DataSource = info.GetRecords();
                    MessageBox.Show("Reservation  Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    dt = info.GetRecords();

                catch (Exception ex)
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

but when i add data then the error show that

Input string is not in correct format???

whr is the problem
and ID is auto generated

Recommended Answers

Best guess? The text for one of your conversions is wrong.

Jump to Post

All 4 Replies


guest name,room no,service type is in comobox

Possibilities for the errors lie in the following lines

35, 37, 38, 39

The Convert.ToInt32 can convert strings like "1", "2" etc. It throws an exception if you try to convert a string like "two", "three", "happy" or even an empty string ""

Likewise the Convert.ToDateTime can only convert strings like date time. If the error lies in these lines try changing the format of the date input you give. Most probably the exception would have been raised here...

Validate the values ( Only numerical values in text boxes ) before the above lines

Use Int.TryParse / DateTime.TryParse for example

P.S. Kindly give us the input that you gave ( that caused the exception )......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.