我不知道如何完成你的任务。
但是,为什么不把问题简单化呢?使用 File DSN 来做:[ODBC]
DRIVER=Microsoft Visual FoxPro Driver
UID=
Deleted=Yes
Null=Yes
Collate=Machine
BackgroundFetch=Yes
Exclusive=No
SourceType=DBF
SourceDB=d:\FoxPro_data这样,你只需要将这个文件存到服务器中,再引用它就是了。
但是,为什么不把问题简单化呢?使用 File DSN 来做:[ODBC]
DRIVER=Microsoft Visual FoxPro Driver
UID=
Deleted=Yes
Null=Yes
Collate=Machine
BackgroundFetch=Yes
Exclusive=No
SourceType=DBF
SourceDB=d:\FoxPro_data这样,你只需要将这个文件存到服务器中,再引用它就是了。
string connectiongstring="Provider=SQLOLEDB.1;Password=;Persist Security Info=False;User ID=sa;Initial Catalog="Sql中的数据库名称";Data Source=Server;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=Server"
OleDbDataAdapter da=new OleDbDataAdapter("select * from 数据表",con);
DataSet ds=new DataSet();
da.Fill(ds,"数据表");
另外有一个方法,写注册表,你查找注册表,看看其他的odbc是如何写的。大约要写两三个地方。具体的我不记得了,你看注册表就行了,很简单的。
Public Sub 创建SQLODBC(ByVal DsnName As String, ByVal Server As String, ByVal UID As String, ByVal Database As String)
'创建SQLDSN "kkk", "USER", "sa", "太原市自来水公司1996"
Dim S As String
Dim A As Long
Dim Driver As String
'Dim SysDir As String * 255
'A = GetSystemDirectory(SysDir, 255)
'WinSysDir = Left(SysDir, A) & "\"
S = String(50, Chr$(0))
'If FS.FileExists(WinSysDir & "SQLSRV32.DLL") And FS.FileExists(WinSysDir & "odbcjt32.dll") Then
'Else
' MsgBox " DSN无法创建,您必须首先安装ODBC,在光盘的ODBC目录下。", vbOKOnly, "安装不完全"
' End
'End If
Driver = GetStringValue("HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\SQL Server", "Driver")
If Driver = "Error" Then
Err.Raise 5000, , "无法创建SQLServerODBC,缺乏必要的文件."
End If
CreateKey "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DsnName & S
SetStringValue "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DsnName & S, "Driver", Driver & S
SetStringValue "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DsnName & S, "Server", Server & S
SetStringValue "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DsnName & S, "Database", Database & S
SetStringValue "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DsnName & S, "LastUser", UID & S
End Sub
string connectiongstring="Provider=SQLOLEDB.1;Password=;Persist Security Info=False;User ID=sa;Initial Catalog="Sql中的数据库名称";Data Source=Server;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=Server"
OleDbDataAdapter da=new OleDbDataAdapter("select * from 数据表",con);
DataSet ds=new DataSet();
da.Fill(ds,"数据表");using System.Data.OleDb;
//加引用public static void Main()
{
OleDbConnection thisConnection=new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Source=C:\……(数据库完整路径)");
thisConnection.Open();
//建立了连接 OleDbCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="select ……";
OleDbDataReader thisReader=thisCommand.ExecuteReader();
//ok!…………
}代码我没有测试,你看一下有什么问题
//加引用public static void Main()
{
OleDbConnection thisConnection=new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Source=C:\……(数据库完整路径)");
thisConnection.Open();
//建立了连接 OleDbCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="select ……";
OleDbDataReader thisReader=thisCommand.ExecuteReader();
//ok!…………
}