Tag : .NET, Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012, VB.NET, Windows
Date :
2014-09-02 11:03:52
By :
yim24052533
View :
1125
Reply :
5
No. 1
Guest
ตอบไปแล้วใน กท. เก่า
ไม่ทราบไม่เข้าใจตรงไหน ???
หรือต้องอธิบายเปนโค้ด ???
วิธีที่ 1 แบบต่อ string
Dim myDate As String: myDate = "2/9/2014";
Dim sql As String: sql = "Select * From [MyTable] Where [MyDate]=Convert(smalldatetime, '" & myDate & "', 103)"
Dim myDate As DateTime: myDate = DateTime.Parse("2/9/2014", System.Globalization.CultureInfo("en-GB"))
Dim sql As String: sql = "Select * From [MyTable] Where [MyDate]=@MyDate"
...
...
command.Parameters.AddWithValue("@MyDate", myDate)
Dim myDate As DateTime: myDate = DateTime.Parse("3/9/2557", System.Globalization.CultureInfo("th-TH"))
Dim sql As String: sql = "Select * From [MyTable] Where [MyDate]=@MyDate"
...
...
command.Parameters.AddWithValue("@MyDate", myDate)