Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Different ways to connect to SQL server
Message
From
19/02/2004 11:25:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00877675
Message ID:
00878752
Views:
13
>I a pretty sure that I am getting close here. When the following code executes I receive an error message that it cannot convert nvarchar to datetime :
>
>oConn.connectionstring = "provider=sqloledb;data source=sweetpea;Integrated Security=SSPI;database=memsales "
> oConn.Open
>
> If oConn.State = 1
> oRs = oConn.Execute("sp_ndcusage_xml memno,ndcnum,sdate,edate")
>
>The procedure has not changed it's parameters are
> memno text
> ndcnum text
> sdate datetime
> edate datetime
>
>The text variables hold and xml value to be converted to a table. This work fine for the following code:
>
> lcsql="exec sp_ndcusage_xml ?memno,?ndcnum,?sdate,?edate"
> lnresult=SQLEXEC(hConn,lcsql,"testdata")
>
>Where and how would I find what is going on and how to fix this data type screw up?
>
>Thanks again
>Kelly

Kelly,
I think we have a miscommunication. Above is for SQL server while the one I provided was for VFP. If you'd call SQL server stored procedure with ADO I think you better use a command object and set its parameters.
m.Start = {^1997/01/01}
m.End = {^1997/03/14}

* Stored proc - ODBC
Local lnHandle
lnHandle=Sqlstringconnect('DRIVER=SQL Server;SERVER=servername;'+;
    'Trusted_connection=Yes;Database=Northwind')
SQLExec(lnHandle,'exec [Sales by Year] ?m.Start, ?m.End','myOrders')
SQLDisconnect(lnHandle)
Browse

* Stored proc - ADO
#Define adDBTimeStamp 135
Local oConn As ADODB.Connection, oCmd As ADODB.Command, ;
  oRS As ADODB.Recordset, oParameter As ADODB.Parameter
oConn = Createobject('ADODB.Connection')
oCmd  = Createobject('ADODB.Command')

oConn.ConnectionString = 'Provider=SQLOLEDB;Data Source=servername;'+;
  'Integrated Security=SSPI;Initial Catalog = Northwind'
oConn.Open
oCmd.ActiveConnection = oConn
oCmd.CommandText = "[Sales by Year]"
oCmd.CommandType = 4 &&adCmdStoredProc
oParameter = oCmd.CreateParameter('Beginning_Date',adDBTimeStamp,,,m.Start)
oCmd.Parameters.Append(oParameter)
oParameter = oCmd.CreateParameter('Ending_Date',adDBTimeStamp,,,m.End)
oCmd.Parameters.Append(oParameter)
oRS = oCmd.Execute

*Show
Showme('Stored proc result',m.oRS)
oRS.Close
oConn.Close

Function Showme
Lparameters tcCaption,toRecordset
oForm = Createobject('myForm', tcCaption,toRecordset)
oForm.Show
Read Events
Endfunc

Define Class myform As Form
  Height = 450
  Width = 750
  Name = "Form1"

  Add Object hflex As OleControl With ;
    Top = 10, Left = 10, Height = 430, Width = 730, Name = "Hflex", ;
    OleClass = 'MSHierarchicalFlexGridLib.MSHFlexGrid'

  Procedure Init
  Lparameters tcCaption,toRecordset
  This.Caption = tcCaption
  This.hflex.Datasource = toRecordset
Endproc
  Procedure QueryUnload
  Clear Events
Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform