Closed WillyAguilera1977 closed 2 years ago
Instead of passing a date literal, try
DIM cvDate AS CVAR cvDate.PutDateString("1/1/1960")
and pass cvDate.
I still can't find the solution to the date problem. The code below causes an infinite loop. What am I wrong? Here is the code that I have already done What should I correct?
' Edit this constant to match your directory structure. Const DBPATH = "NWind.mdb" Dim cmd As CADOCommand ' , rs As CADORecordset
cmd.CommandType = adCmdText cmd.CommandText = "Select * From Employees Where BirthDate > ? " & "AND HireDate > ?" cmd.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= " & DBPATH ' You can use a temporary Parameter variable.
Dim cvDate As CVAR cvDate.PutDateString("1/1/1960")
Dim param As CADOParameter = cmd.CreateParameter("BirthDate", adDate, adParamInput, , cvDate)
'param.Value = cvDate
Dim cvDate2 As CVAR cvDate2.PutDateString("1/1/1993") ' Dim param2 As CADOParameter = cmd.CreateParameter("HireDate", adDate, adParamInput, , cvDate2) ' 'param2.Value = cvDate2 ' Dim params As CADOParameters = cmd.Parameters params.Append(param) params.Append(param2) ' Dim rs As CAdoRecordset = cmd.Execute 'Print rs.RecordCount
' Parse the recordset Do ' // While not at the end of the recordset... If rs.EOF Then Exit Do
Print rs.Collect("FirstName")
Print rs.Collect("LastName")
' // Fetch the next row
If rs.MoveNext <> S_OK Then Exit Do
Loop
Print Print "Press any key..." Sleep
Waiting for your answer, I greet you very sincerely
I don't see nothing wrong, but you don't do any error checking. Each object has a GetlastResult method. print cmd.GetLastResult after cmd.CreateParameter and so on.
Hello again. I solved the problem. It was my mistake. I wrote it wrong. Thank you very much for the help. I congratulate you for the framework is wonderful.
I need to translate this program from Visual Basic 6.0 to FreeBasic. The problem is date literals that don't exist in FreeBasic. What do I have to do. Thanks very much in advance.
' Edit this constant to match your directory structure. Const DBPATH = "C:\Program Files\Microsoft Visual Studio\Vb98\NWind.mdb" Dim cmd As New ADODB.Command, rs As New ADODB.Recordset cmd.CommandText = "Select * From Employees Where BirthDate > ? " & "AND HireDate > ?" cmd.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= " & DBPATH ' You can use a temporary Parameter variable. Dim param As ADODB.Parameter Set param = cmd.CreateParameter("BirthDate", adDate, , , #1/1/1960#) ' this is the problem date literals cmd.Parameters.Append param ' Or you can do everything in one operation. cmd.Parameters.Append cmd.CreateParameter("HireDate", adDate, , , _
1/1/1993#)
Set rs = cmd.Execute(, , adCmdText) Waiting for your answer, I greet you very sincerely