hello all

i am new to C#

i want to enter a datetime value in table

but when i give datetime datatype in insert statement it is not displaying any error while executing

but when i see the inserted value in my table it shows

1900/01/01

i want to enter this in DD/MM/YYYY format

How can i do this ????
Please Help me.


Thanks

This is my code

in this getdate() is working good but when i am adding months in the current date
it give wrong value to table.

[B]DateTime date1 = DateTime.Now.AddMonths(Convert.ToInt32(m1.Text.Trim()));[/B]
strBill = "Insert into bill values(" + billno.Text.Trim() + ",[B]getdate()[/B],'" + cName.Text.Trim() + "','" + add1.Text.Trim() + "','" + add2.Text.Trim() + "','" + add3.Text.Trim() + "','" + phone.Text.Trim() + "'," + total.Text.Trim() + ")";
strSale1 = "insert into sale values(" + billno.Text.Trim() + ",'" + type1 + "','" + PID1.Text.Trim() + "','" + bName1.Text.Trim() + "','" + va1.Text.Trim() + "'," + [B]date1.ToShortDateString()[/B] + "," + amount1.Text.Trim() + ")";
                    db.Connect();
                    db.insert(strBill);
                    db.insert(strSale1);
                    db.Disconnect();

I'm not getting any kind of error in this code
problem is I'm not getting the right output


I want to enter the date in DD/MM/YYYY format and also the right date

this code insert date in table in right format

but date is always 01/01/1900


i have try this sql statement in sql-server 2000 without quoting the datetime string in my statement. it works fine.

but when i try this with quoting it give the following error: -

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

try using date1.ToString("MM/dd/yyyy") . Don't worry about how the database stores the date as you'll be able to format it however you want when you display it.

hello all

please help me to solve the date problem

i dont find any solution to this problem

thanks in advance
help

hello all

i am new to C#

i want to enter a datetime value in table

but when i give datetime datatype in insert statement it is not displaying any error while executing

but when i see the inserted value in my table it shows

1900/01/01

i want to enter this in DD/MM/YYYY format

How can i do this ????
Please Help me.


Thanks

This article has been dead for over six months. Start a new discussion instead.