Hi everyone,
iam trying to convert a gridview cell value (input by user) into datetime.
i tried almost all methods to convert but into vain. working on this from past 3 weeks. plz help...
my code:
string connectionstring = WebConfigurationManager.ConnectionStrings["RoyalHotelManagement"].ConnectionString;
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand("InsertSuite", con);
cmd.CommandType = CommandType.StoredProcedure;
string filleddate = GridView2.Rows[e.RowIndex].Cells[2].Text;
string freedate = GridView2.Rows[e.RowIndex].Cells[3].Text;
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-US", true);
DateTime filleddate1 = DateTime.ParseExact(filleddate, "mm/dd/yyyy HH:mm:ss", theCultureInfo);
DateTime freedate1 = DateTime.ParseExact(freedate, "mm/dd/yyyy HH:mm:ss", theCultureInfo);
cmd.Parameters.AddWithValue("@filleddate", filleddate1);
cmd.Parameters.AddWithValue("@freedate", freedate1);
cmd.Parameters.AddWithValue("@nameofcustomer", GridView2.Rows[e.RowIndex].Cells[6].Text);
try
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
}
finally
{
con.Close();
}
my storedprocedure:
ALTER PROCEDURE InsertSuite
@filleddate datetime,
@freedate datetime,
@nameofcustomer varchar(50)
AS
BEGIN
SET NOCOUNT ON
Insert into PresidentialSuite(DateWhenFilled,DateWhenFree,NameOfCustomer)
values (@filleddate,@freedate,@nameofcustomer);
END
i tried even with update.... no use
thanks in advance..
Loading
suni dotnetPosted Jan 10, 2009, 2:02 PM
hi,
i tried all methods as i said, even parse, but couldnot find a solution, so instead of updating gridview, i used textboxes to take input and then updated gridview with these values.
thanks for ur reply, i'll try with MM also...
thanks once again
Guest UserPosted Jan 9, 2009, 4:02 PM
"mm" is minutes. "MM" is month. Datetime format strings are case-sensitive.
Guest UserPosted Jan 9, 2009, 3:55 PM
Instead of ParseExact, why not try Parse? Then you don't need to specify a format and the framework can determine the date from the string.
suni dotnetPosted Jan 9, 2009, 1:44 PM
2/2/2008,02/02/2008,2/2/2008 12:02:02,2/2/2008, 10:09am,2008/02/02
Guest UserPosted Jan 9, 2009, 1:12 PM
Can you copy & paste a date directly from your grid into a post here?
suni dotnetPosted Jan 9, 2009, 1:06 PM
convert.todatetime,stored procedureformat, datetime.parse
all methods gave me the same error
Guest UserPosted Jan 9, 2009, 12:53 PM
Since you're using DateTime.ParseExact, the grid datetimes must match that format exactly or the parse will fail.