set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[updatereserveinfo]
@Reservation_ID int,
@guest_id int,
@Room_id int,
@service_id int,
@no_of_days int,
@check_in datetime,
@check_out datetime
as
begin
update Reservation
set
Guest_ID=@guest_id,Room_ID=@Room_id,Service_ID=@service_id,No_of_days=@no_of_days,Check_in=@check_in,Check_out=@check_out
where Reservation_ID=@Reservation_ID
end
Actually the problem is regarding your date column (Check-in & Check-out)
There may be 2 possibilities
1) your column date format and passing values date format is different that's why it is throwing an error. I mean if your Database table date format is dd-mm-yyyy and you are passing yyyy-mm-dd then it is throwing error, you need to play around with it.
2) If you have created check-in & check-out as varchar column in your table and if you try to insert date value then it will give you the error, you need to write like 'check-in' and 'check-out' (prefix and suffix with single qoute)
Marked as answer by Amy Peng - MSFT on Dec 17, 2012 12:31 AM
AMBER ASHIQ
Member
1 Points
24 Posts
Input string is not in correct format???
Dec 09, 2012 02:21 AM|LINK
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); con.Open(); 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)); com.ExecuteNonQuery(); con.Close(); } add button private void add_Click_2(object sender, EventArgs e) { try { 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); manage.addreserve(); dataGridView1.DataSource = info.GetRecords(); MessageBox.Show("Reservation Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.Clear(); 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
i hve also create store procedures
how to solve this????
oned_gk
All-Star
31798 Points
6499 Posts
Re: Input string is not in correct format???
Dec 09, 2012 02:37 AM|LINK
I think the problem from culture format.
or try this
or try combination date in textbox like 25/12/2012 and 12/25/2012 is either work?
AMBER ASHIQ
Member
1 Points
24 Posts
Re: Input string is not in correct format???
Dec 09, 2012 06:12 AM|LINK
this is not working =(
oned_gk
All-Star
31798 Points
6499 Posts
Re: Input string is not in correct format???
Dec 09, 2012 06:44 AM|LINK
try change page culture fit to your sql
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.71).aspx
CommDev
Member
112 Points
26 Posts
Re: Input string is not in correct format???
Dec 09, 2012 07:54 AM|LINK
According to the error message “Input string is not in correct format”, the exception is thrown by the Convert functions.
You can just check the “Convert.ToInt32” and “Convert.ToDateTime” functions if the input is not a valid integer or date time.
AMBER ASHIQ
Member
1 Points
24 Posts
Re: Input string is not in correct format???
Dec 10, 2012 03:07 PM|LINK
In this when i updated data then not updated it is deleted in update button but there is update fuction
how i solve this problem that data are update????/
here is updated fuction
public void updatereserve() { string constring = @"Data Source=.\SQLEXPRESS;Database=htm;Integrated Security=True"; SqlConnection con = new SqlConnection(constring); con.Open(); DataTable dt = new DataTable(); SqlCommand com = new SqlCommand("updatereserveinfo", 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)); com.ExecuteNonQuery(); con.Close(); and here is update button codeprivate void UPDTE_Click(object sender, EventArgs e) { try { Reservation_manager manage = new Reservation_manager(info); info.Reservation_ID1 = Convert.ToInt32(txt_reser.Text); info.Guest_name = text_guest.SelectedValue.ToString(); 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 = DateTime.Parse(check_out.Text); manage.updatereserve(); //dataGridView1.DataSource = info.GetRecords(); MessageBox.Show("Reservation Update Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.Clear(); dt = info.GetRecords(); dataGridView1.DataSource = dt; clearfield(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }code
abhij1987
Member
24 Points
7 Posts
Re: Input string is not in correct format???
Dec 10, 2012 04:24 PM|LINK
Hi,
Actually the problem is regarding your date column (Check-in & Check-out)
There may be 2 possibilities
1) your column date format and passing values date format is different that's why it is throwing an error. I mean if your Database table date format is dd-mm-yyyy and you are passing yyyy-mm-dd then it is throwing error, you need to play around with it.
or try
com.Parameters.Add(new SqlParameter("@Check_in", Convert.ToDateTime(myreserv.Check_in)));
com.Parameters.Add(new SqlParameter("@Check_out", Convert.ToDateTime(myreserv.Check_out)));
2) If you have created check-in & check-out as varchar column in your table and if you try to insert date value then it will give you the error, you need to write like 'check-in' and 'check-out' (prefix and suffix with single qoute)
AMBER ASHIQ
Member
1 Points
24 Posts
Re: Input string is not in correct format???
Dec 10, 2012 04:58 PM|LINK
this is solve i hve asking another question whcih i posted
question is about when i update data then istead of update the data is deleted form gridview but updated in sql
and thanku fo rreply andhelping
abhij1987
Member
24 Points
7 Posts
Re: Input string is not in correct format???
Dec 11, 2012 03:43 AM|LINK
after updating you need to rebind your gridview.
AMBER ASHIQ
Member
1 Points
24 Posts
Re: Input string is not in correct format???
Dec 11, 2012 06:59 AM|LINK
how i done this