Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in insert query for date

Status
Not open for further replies.

andypower

Programmer
Aug 10, 2004
23
IN
hi
my self andy, i am developing one application in vb 6 and sqlserver 7 as back end. i write one insert query for inserting one record. there is one voucherdate fied. to which i am passing my date value as a parameter. bu when i execute that query it stores 01/01/1999 instead of my pass data. plz give me some suggestion on this.
my query.

insert into voucher(voucherno,name,amount,Voucherdate)
values(" & txtvoucherno.text & ",'" & txtname.text & "'," & txtamount.text & ",'" & format(txtvoucherdate.text,"dd/mm/yyyy") & "')

out put
insert into voucher(voucherno,name,amount,Voucherdate)
values(1,'Andy',5000,'05/04/2004')

though here it show voucherdate '05/04/2004' but it stores in database as 01/01/1999.
 
Try doing the conversion in SQL instead:
Code:
insert into voucher(voucherno,name,amount,Voucherdate)
values(" & txtvoucherno.text & ",'" & txtname.text & "'," & txtamount.text & ",CONVERT(DateTime,'" & txtvoucherdate.text & "',103))


Bob Boffin
 
Even better would be to write a stored procedure and send the parameter data rather than the T-SQL statement.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top