VFP中怎么与SQL SERVER连接,前提是不用ODBC
1个回答
展开全部
vfp中用ado访问sql数据库
*----------------------------
FUNCTION DalBuildMarket(vMarket as String,curName as String ) as integer
PRIVATE all
result=0
storeProd = "TOWNSelByName2 "
this.strConn= "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=test;Data Source=127.0.0.1 "
TRY
***********************
LOCAL oConn AS ADODB.Connection,cStrung AS Character,oRs AS ADODB.RecordSet,oCmd AS ADODB.Command
oConn=CREATEOBJECT( "ADODB.Connection ")
oConn.Open(this.strConn)
oCmd=CREATEOBJECT( "ADODB.Command ")
oCmd.ActiveConnection=oConn
oCmd.CommandText=storeProd
oCmd.CommandType=4 && 调用存储过程
**初始化参数
oCmd.Parameters.Append(oCmd.CreateParameter( "vProName ",200,1,100, " "))
oCmd.Parameters.Append(oCmd.CreateParameter( "vTownName ",200,1,100, " "))
**赋值
oCmd.Parameters( "vTownName ").Value=vMarket
oRs=oCmd.Execute()
DO WHILE NOT oRs.EOF
INSERT INTO (curName) (id,provinceName ,TownName ) value(oRs.Fields(0).Value ,oRs.Fields(1).Value ,oRs.Fields(2).Value )
ors.MoveNext
result=result+1
ENDDO
oConn.Close()
CATCH
IF oConn.State <> 0
oConn.Close()
ENDIF
result=-1
ENDTRY
RETURN result
ENDFUNC
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询