Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SqlDataAdapter da = new SqlDataAdapter("select * from VisitorPass where PassNo = " + vtxtsearch.Text.Trim(), objConn);
       DataSet ds = new DataSet();
       da.Fill(ds, "VisitorPass");
       if (ds.Tables["VisitorPass"].Rows.Count > 0)
       {
           vtxtpassno.Text = ds.Tables["VisitorPass"].Rows[0]["PassNo"].ToString();
           vtimein.Text = DateTime.Parse(vtxtdate.Text).ToString();
           vtimeout.Text = DateTime.Parse(vtxtdate.Text).ToString();
           vtxtvisitorName.Text = ds.Tables["VisitorPass"].Rows[0]["VisitorsName"].ToString();
           vtxtpurpose.Text = ds.Tables["VisitorPass"].Rows[0]["Purpose"].ToString();
           vtxttosee.Text = ds.Tables["VisitorPass"].Rows[0]["ToSee"].ToString();


       }


using above code

give error on
vtimein.Text


String was not recognized as a valid DateTime.


date format is 2015-02-10 12:59:00.000

could y pls help me out with code


kindly help
thx in advance
Posted
Updated 5-Feb-15 1:46am
v3

The format getting entered in textbox might be incorrect.
Apply validations for validating the format.
 
Share this answer
 
Comments
Master Vinu 5-Feb-15 5:37am    
how to apply pls expalain in code
nagendrathecoder 5-Feb-15 5:41am    
Check google.
https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=validate%20datetime%20format%20in%20c%23
Master Vinu 5-Feb-15 6:00am    
date format is 2015-02-10 12:59:00.000

could y pls help me out with code

thx
You should use DateTime.ParseExact[^] to convert it the string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information.
Alternatively, you can use DateTime.TryParseExact[^] which will return a value that indicates whether the conversion succeeds.
 
Share this answer
 
v2
Comments
Master Vinu 5-Feb-15 5:53am    
date format is 2015-02-10 12:59:00.000

could y pls help me out with code

thx
vtimein.Text = ds.Tables["VisitorPass"].Rows[0]["Date"].ToString();
 
Share this answer
 

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