Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my query in sql server


HTML
INSERT INTO dbo.KaunselingDT (NoKaunselor, NoPerakuan, Date)VALUES('123', '456', '14 / Oktober / 2014')


And this is my Save() button in VB.Net


HTML
sql = "INSERT INTO dbo.KaunselingDT (NoKaunselor, NoPerakuan, Date)" _
                & "VALUES('" & Me.txtNoKaunsDaftar.Text & "', '" & Me.txtNoAkuanAmalan.Text & "', '" & Me.lblDate.Text & "')"


How to change the lblDate to smalldatetime data type?
Posted
Updated 13-Oct-14 21:49pm

Use SqlParameters instead. Your solution is extremely unsafe and prone to sql-injection. Also, I ensure you to get errors when the server does not use the same date format as the client. Please check out the article below and do it the right way!

http://vbnetsample.blogspot.nl/2007/10/using-sqlparameter-class.html[^]

Using SQLParameters with VB.NET/C#[^]

Good luck!
 
Share this answer
 
Comments
U_Hanisa 14-Oct-14 22:33pm    
TQ. ^_^
VB
Dim formatInfo As New DateTimeFormatInfo()
formatInfo.ShortDatePattern = "dd/MM/yyyy"
formatInfo.DateSeparator = "/"
Dim objDate As DateTime = Convert.ToDateTime(Me.lblDate.Text, formatInfo)</pre>
 
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