真的沒人會嗎 (100分)

  • 主题发起人 主题发起人 goddy
  • 开始时间 开始时间
G

goddy

Unregistered / Unconfirmed
GUEST, unregistred user!
在asp 里这样可以
conStr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+server.MapPath(".")+"/DATA.MDB"
Dim objADOXDatabase
Set objADOXDatabase = Server.CreateObject("ADOX.Catalog")
objADOXDatabase.ActiveConnection = conStr
///////////////////就這几句 asp試調試通過了


下面不面的會出錯

在delphi
var
MSWord2000,objADOXDatabase,objTable: OLEVariant;
conStr,FileName:String;
begin
if OpenDialog1.Execute then
FileName:=OpenDialog1.FileName;
conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Engine Type=5;Password="";User ID=Admin;Data Source='+FileName;
objADOXDatabase := CreateOleObject('ADOX.Catalog');
objADOXDatabase.ActiveConnection:=conStr;//到这边出错,说是:
'[Microsoft][odbc 驱动程序管理器]未发现数据源名称并且未指定默认驱动程序'

end;
为什么呢,我写样没错的 conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Engine Type=5;Data Source=E:/Data/EMail.mdb'
谁能说下呢
thanks




 
用ADO组件试试看..看看还有没有错误
 
单步执行看看你的Constr是否对,也许FileName没有包含扩展名.
 
你可以先用ADO组件的向导方式连接一下,连接测试成功后,再将其connectionString属性
里的字符串拷到代码里,涉及到文件名及路径的地方作一下相应的修改。
 
to coolcat toHunterTeam, 我都試了不行的
我单步执行時conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Engine Type=5;Data Source=E:/Data/EMail.mdb'
都不行
 
VB项目中建立对Microsoft ADOExt.2.1 for DDL and Security(文件名为MSADOX.Dll)的引用后,下列代码演示在SQL Server 7.0的Pubs数据库中增加一个名为Test,包含一个名为Column1,类型为varChar,大小为50列的表。
例子代码:
Dim objPubs As New Connection
Dim objCatalog As New ADOX.Catalog
Dim objTable As New ADOX.Table

objPubs.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)"
objPubs.Open

Set objCatalog.ActiveConnection = objPubs


new Connection 是什么東東呢,奇怪VB里Set objCatalog.ActiveConnection = objPubs 為什么要加一下 set呢 不直接寫成objCatalog.ActiveConnection = objPubs ???
 
new Connection 是什么東東呢,奇怪VB里Set objCatalog.ActiveConnection = objPubs
為什么要加一下 set呢 不直接寫成objCatalog.ActiveConnection = objPubs ???
这个是VB的语法,new Connection是生成一个Connection的实例.
Activeconnection是一个对象,不是一个字符串,你可以生成一个连接对象测试一下.


 
objADOXConn := CreateOleObject('ADOX.Connection');
objADOXConn.open Connectionstring;
objCatalog.ActiveConnection:=objADOXConn;
 
procedure TForm1.Button1Click(Sender: TObject);
var
MSWord2000,objADOXDatabase,objTable,objPubs: OLEVariant;
conStr,FileName:String;
begin
//if OpenDialog1.Execute then
// FileName:=OpenDialog1.FileName;
// conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Password="";User ID=Admin;Data Source='+FileName;
conStr:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=sd3';
objADOXDatabase := CreateOleObject('ADOX.Catalog');
objPubs:=CreateOleObject('ADOdb.Connection');
objPubs.ConnectionString:=conStr;
objPubs.Open;
objADOXDatabase.ActiveConnection:=objPubs;
end;


end.
我寫成這樣也不行
 
ADOX.Connection 不是對像
 
ActiveConnection Property (ADO MD)


The ActiveConnection property indicates to which Connection object the current
Cellset or Catalog currently belongs.

Settings and Return Values

ActiveConnection sets or returns a Variant that contains a String defining
a connection or Connection object. Default is empty. ActiveConnection is
read/write.

Remarks

You can set this property to a valid ADO Connection object or to a valid
connection string. When this property is set to a connection string,
the provider creates a new Connection object using this definition and
opens the connection.
If you use the ActiveConnection argument of the Open method to open a Cellset
object, the ActiveConnection property will inherit the value of the argument.

Setting the ActiveConnection property of a Catalog object to Nothing releases
the associated data, including data in the CubeDefs collection and any related
Dimension, Hierarchy, Level, and Member objects. Closing a Connection object
that was used to open a Catalog has the same effect as setting the
ActiveConnection property to Nothing.

An error will occur if you attempt to change the ActiveConnection property
for an open Cellset object.

Note Remember to use the Set keyword when setting the ActiveConnection
property to a Connection object. If you omit the Set keyword you will actually
be setting the ActiveConnection property equal to the Connection object's
default property: ConnectionString. The code will work; however, you will
create an additional connection to the data source, which may have
negative performance implications.

 
首先你import tpye library--------adox
adoxCatalog := CoCatalog.Create;
//adoxcatalog.create//建库
adoxcatalog.Set_ActiveConnection(
..........
adoxcatalog := nil
 
1。 导入adox
2。 放控件到form上或动态Create
3. adoxCatalog.connect;
4. adoxcatalog.Set_ActiveConnection(cnn_str)

 
我要的其實就是要把這几句用delphi 寫而已
Dim cat As New ADOX.Catalog

cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;_
Persist Security Info=True;Data Source=" + “c:/r2k.mdb" + ";_
Jet OLEDB:Database Password='123456'"

‘连接数据库

Dim i As Integer

Dim j As Integer

For i = 0 To cat.Tables.Count – 1 ‘循环所有表单

Debug.Print "表单名称:" + cat.Tables(i).Name

For j = 0 To cat.Tables(i).Columns.Count – 1 ‘循环表单所有字段

Debug.Print "字段名称:" + cat.Tables(i).Columns(j).Name

Debug.Print "字段类型:" + GetDataTypeEnum(cat.Tables(i).Columns(j).Type)

Debug.Print "字段大小:"; Format(cat.Tables(i).Columns(j).DefinedSize)

Next

Next

Set cat=Nothing
 
extractfilename()
 
conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Engine Type=5;Password="";User ID=Admin;Data Source='+FileName;
改为
conStr:='Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Engine Type=5;Password="";User ID=Admin;Data Source="'+FileName + '"';
 
不是conStr 的問題﹐我看過了
 
objADOXDatabase.ActiveConnection:=conStr中,conStr是字符串,但是objADOXDatabase.ActiveConnection要求的是Adoconnection接口,所以,有两种改法:
1)用objAdoxDatabase.Connectionstring:=conStr
2)adoCn:=TAdoConnection.Create(self);
adoCn.ConnectionString:=conStr;
objAdoxDatabase.ActiveConnection:=adoCn;
 
to lajfox
1)用objAdoxDatabase.Connectionstring:=conStr //沒有這個Connectionstring obj
2)adoCn:=TAdoConnection.Create(self);
adoCn.ConnectionString:=conStr;
objAdoxDatabase.ActiveConnection:=adoCn; 這樣子也不行呀
 
后退
顶部