Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using calenderExtender on TextBox which pick the date and store it in text box but problem is when i want to store this selected date in Save button click it throws exception
In SQL field i also mention StockDate datetime. On Save button click event i write code:
C#
objBusinessUI.StockDate = Convert.ToDateTime(txtStockDate.Text);

and i also try
C#
objBusinessUI.StockDate = Convert.ToDateTime(txtStockDate_CalendarExtender.SelectedDate);

but it not works
In DAL file
C#
SqlParameter StockDate = new SqlParameter("@StockDate", objStock.StockDate);
                   StockDate.Direction = System.Data.ParameterDirection.Input;
                   StockDate.DbType = System.Data.DbType.DateTime;
                   sqlParams[2] = StockDate;


so please help me
Thnx in advance
Posted
Updated 22-Sep-13 20:19pm
v2

I think it is mismatch between the date formats between your dev machine and the sql server machine datetime. Have a look on your computer Regional settings to see your system date time format.

Also use ;
C#
DateTime dt = DateTime.ParseExact(TextBox.Text, "dd/MM/yyyy", 
                                  CultureInfo.InvariantCulture);

Good luck,
OI
 
Share this answer
 
Hi,

txtStockDate_CalendarExtender.SelectedDate might be returning an invalid string format of date time as Convert.ToDateTime takes the string of form mm/dd/yyyy.

Try this.
 
Share this answer
 
objBusinessUI.StockDate = Convert.ToDateTime(txtStockDate.Text.Tostring());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900