 |
|
สอบถามการดึงข้อมูล SQL กับ .net เวลาดึงข้อมูล โดยใช้เงื่อนไขวันที่มันดึงมาไม่ได้ |
|
 |
|
|
 |
 |
|
ต้องใส่เขาเดี่ยวให้มันครับ ' วันที่ '
select top 1 DocNo from BCQuotation where DocDate = '23/1/2558 0:00:00' // ต้องเอามาทั้งชุด
select * from BCQuotation where convert(VARCHAR, ModifiedDate, 103)= '27/09/2010' // เอาแค่วันที่ต้องแปลง Format ก่อน
|
 |
 |
 |
 |
Date :
2015-01-23 12:38:01 |
By :
thaidevelopment.net |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีปัยหาเรื่อง Format อีกแน่นอนครับ แนะนำให้ใช้แบบนี้
Code (SQL)
select DocDate from BCQuotation where convert(VARCHAR, DocDate, 103)= '23-Jan-2015'
|
 |
 |
 |
 |
Date :
2015-01-23 14:27:26 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นลอง ใช้คำสั่ง Select ข้อมูลตามด้านล่างดูก่อนครับ แล้วเอามาแปะในเว็บให้ผมดูหน่อยครับ
Code (SQL)
select convert(VARCHAR, DocDate, 103) from BCQuotation
|
 |
 |
 |
 |
Date :
2015-01-23 14:51:31 |
By :
thaidevelopment.net |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ิิถ้าดึงแบบไม่มีเงือนไขมันออกคับ

|
ประวัติการแก้ไข 2015-01-23 14:57:26
 |
 |
 |
 |
Date :
2015-01-23 14:57:01 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (SQL)
select DocDate from BCQuotation where convert(VARCHAR, DocDate, 103)= '23/01/2015'
|
 |
 |
 |
 |
Date :
2015-01-23 15:07:28 |
By :
thaidevelopment.net |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ลองดูครับ
อันนี้ code ที่ลองใน sql
select top 1 DocNo from BCQuotation where DocNo LIKE '%QA58%' AND DocDate = '23/1/2015'
อ๊อ 2558 มันจะไม่เจอนะครับ เพราะ database 2015
แต่ก็ตามพี่วินบอกครับปัญหาเกิดจาก format
ลอง ก๊อบขอมูลมาเปลี่ยนใน 23/1/2015 ดูครับ แต่อย่าลืมต้องมี ' ' สำหรับวันที่
    
|
 |
 |
 |
 |
Date :
2015-01-23 15:15:32 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคนคับ ได้ละ
Code (SQL)
select top 1 DocNo from BCQuotation where DocNo LIKE '%QA58%' AND convert(VARCHAR, DocDate, 103)= '23/01/2015' order by DocNo DESC
แต่....
ผมจะเปลี่ยน Format ใน asp.net ไงคับ มันยังเป็น 23/1/2558 อยู่เลยคับ
Code (VB.NET)
If day1 = "1" Then
Dim str_date As String = ""
Dim date1_a As Date = Date.Now.ToShortDateString
str_date = day2.ToShortDateString
'MsgBox(str_date)
sql = "select top 1 DocNo from BCQuotation where DocNo LIKE '%QA58%' AND convert(VARCHAR, DocDate, 103)= '" & str_date & "' order by DocNo DESC"
da = New SqlDataAdapter(sql, cn)
dt2 = New DataTable
da.Fill(dt2)
If dt.Rows.Count > 0 Then
GridView1.DataSource = dt2
GridView1.DataBind()
'Dim day_chack As Date = Date.Now.ToShortDateString
'day_chack = dt2.Rows(0).Item("DocNo")
'MsgBox(day_chack)
End If
Else
cut_str2 = cut_str2 + 1S
End If
|
ประวัติการแก้ไข 2015-01-23 15:25:14
 |
 |
 |
 |
Date :
2015-01-23 15:23:58 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|