我写的程序总说ODBC连接连接失败,高手可看看什么原因,有更好的源程序吗?介绍介绍:
String ls_path,ls_file
Long ll_rc
ll_rc = GetFileOpenName('请选择DBF文件位置',ls_path,ls_file,&
"DBF",'DBF文件(*.dbf),*.dbf',getcurrentdirectory (),2+2^3+2^4+2^6+2^14+2^15)
If ll_rc <> 1 Then Halt
ls_path = Left(ls_path,Len(ls_path) - Len(ls_file) - 1 )
sqlca.DBMS = "ODBC"
sqlca.AutoCommit = False
sqlca.DBParm = "ConnectString='"+&
"DRIVER=Microsoft FoxPro VFP Driver(*.dbf);"+&
"UID=admin;"+&
"UserCommitSync=Yes;"+&
"Threads=3;"+&
"Statistics=0;"+&
"SafeTransactions=0;"+&
"PageTimeout=600;"+&
"MaxScanRows=8;"+&
"MaxBufferSize=2048;"+&
"FIL=dBase 5.0;"+&
"DriverId=533;"+&
"Deleted=1;"+&
"DefaultDir="+ls_path+";"+&
"CollatingSequence=ASCII;" + "'"
CONNECT Using sqlca;
If sqlca.SQLCode = -1 Then
MessageBox('apptitle',"ODBC数据库连接失败!")
Destroy sqlca
Return
Else
SetPointer(hourglass!)
DataStore ds_test
String ls_syntax,ls_sql,ls_style,ls_err
ls_sql = "Select * from "+Left(ls_file,Len(ls_file) - 4)
ls_style = "style(type=grid)"
//创建DataWIndow(DataStore)的源代码
ls_syntax = sqlca.SyntaxFromSQL(ls_sql,ls_style,ls_err)
If Len(ls_err) > 0 Then
MessageBox("Error","创建DataStore源代码失败:" + ls_err)
Else
//用DataStore来连接,并读取数据
// DataStore ds_test
ds_test = Create DataStore
ds_test.Create(ls_syntax,ls_err)
If Len(ls_err) > 0 Then
MessageBox("Error","创建DataStore出错:" + ls_err)
Else
ds_test.SetTransObject(sqlca)
ds_test.Retrieve()
ll_rc = ds_test.saveas(ls_path + '\'+Left(ls_file,Len(ls_file) - 4 )+'.txt',Text! ,true )
if ll_rc = 1 then
messagebox('提示张勇','转换TXT文件成功!~r~n'+ls_path + '\'+Left(ls_file,Len(ls_file) - 4 )+'.txt')
else
messagebox('提示张勇','转换TXT文件失败!',stopsign!)
end if
End If
Destroy ds_test
End If
End If