Dim CNN As Connection
Dim rs As Recordset
Dim ssql As String 'sql to be used to manipulate datebase
Dim serverip As String 'ip of server or "localhost" if its on your machine
Dim port As String 'port used my MySql 3306 by default
Dim user As String 'username
Dim datebasename As String 'database name
Dim password As String 'password
Dim table_name As String 'table to manipulate
'Setting variables
serverip = "localhost"
port = "3306"
datebasename = "test"
user = "sa"
password = "sa"
table_name = "surveil_member"
Dim a As String
a = "2013-6-1"
'Creating a new connection, and defineing the variables
Set CNN = New Connection
CNN.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=" & serverip & ";" _
& " DATABASE=" & datebasename & ";" _
& " PORT=" & port & ";" _
& "UID=" & user & ";PWD=" & password & "; OPTION=3"
CNN.Open 'Opening the database
Set rs = New Recordset 'Rs allows you to move through the records with simple commands such as rs.MoveNext
ssql = "select count(*) as cc from " & table_name & " where vstdate='" & a & "'"
rs.Open ssql, CNN 'activates the sql
debug.print ssql
MsgBox rs("cc") 'show record
Set rs = Nothing 'To reduce bugs rs and cnn are set to nothing.
CNN.Close
Set CNN = Nothing
End Sub
คือ ถ้าผมใช้ ssql = "select count(*) as cc from " & table_name
ผลลัพธ์ออกมาเป็นตัวเลขจำนวนเรคคอร์ดที่มีอยู่ในฐานนะครับ แต่ผมงงตอนผมใส่ where เข้าไปทำไมผลลัพธ์เป็น 0 ตลอด ทั้งที่ผมเอา sql ที่ debug ไปทดสอบดูแล้ว ข้อมูลก็ออกนะครับ ไม่ใช่ 0 เรคคอร์ด
sql มัน error ช่วยดูให้หน่อยครับ - VB6
Dim rs As Recordset
Dim ssql As String 'sql to be used to manipulate datebase
Dim serverip As String 'ip of server or "localhost" if its on your machine
Dim port As String 'port used my MySql 3306 by default
Dim user As String 'username
Dim datebasename As String 'database name
Dim password As String 'password
Dim table_name As String 'table to manipulate
'Setting variables
serverip = "localhost"
port = "3306"
datebasename = "test"
user = "sa"
password = "sa"
table_name = "surveil_member"
Dim a As String
a = "2013-6-1"
'Creating a new connection, and defineing the variables
Set CNN = New Connection
CNN.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=" & serverip & ";" _
& " DATABASE=" & datebasename & ";" _
& " PORT=" & port & ";" _
& "UID=" & user & ";PWD=" & password & "; OPTION=3"
CNN.Open 'Opening the database
Set rs = New Recordset 'Rs allows you to move through the records with simple commands such as rs.MoveNext
ssql = "select count(*) as cc from " & table_name & " where vstdate='" & a & "'"
rs.Open ssql, CNN 'activates the sql
debug.print ssql
MsgBox rs("cc") 'show record
Set rs = Nothing 'To reduce bugs rs and cnn are set to nothing.
CNN.Close
Set CNN = Nothing
End Sub
คือ ถ้าผมใช้ ssql = "select count(*) as cc from " & table_name
ผลลัพธ์ออกมาเป็นตัวเลขจำนวนเรคคอร์ดที่มีอยู่ในฐานนะครับ แต่ผมงงตอนผมใส่ where เข้าไปทำไมผลลัพธ์เป็น 0 ตลอด ทั้งที่ผมเอา sql ที่ debug ไปทดสอบดูแล้ว ข้อมูลก็ออกนะครับ ไม่ใช่ 0 เรคคอร์ด