谢谢上两位兄弟,我想访问一个表--tbStudnet,程序是这样的: adocnnt.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False'; tbStudent.Connection:=adocnnt; tbStudent.TableName:='student'; tbStudent.Active:=true; tbStudent.open; tbStudent.Insert; tbStudent.InsertRecord([4,'小赵','男']); tbStudent.Close; 但是,编译时出现如下错: [Warning] Unit2.pas(40): Variable 'tbStudent' might not have been initialized [Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized
[Warning] Unit2.pas(40): Variable 'tbStudent' might not have been initialized [Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized -->你是动态创建的? 如果可以,贴出完整的代码
情况是这样的:为连接Access数据库(只有一张表student),我用了如下部件ADOConnection,ADOTable,DataSource和DBGrid.其中ADOConnection的Connection属性是:'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False'.当然罗,ADOTable连在ADOConnectio上,其Active属性设为True,TableName属性设为student.DataSource连在ADOTable上,DBGrid连在DataSource上,这时,DBGrid已成功显示了表的内容.我想在数据库中增加一条纪录,程序段如下: var tbStudent: TADOTable; adocnnt: TADOConnection; begin adocnnt.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False'; tbStudent.Connection:=adocnnt; tbStudent.TableName:='student'; tbStudent.Active:=true; tbStudent.open; tbStudent.Insert; tbStudent.InsertRecord([4,'小赵','男']); tbStudent.Close; DBGrid1.Refresh; end; 编译时出现如下警告错误: [Warning] Unit2.pas(40): Variable 'tbStudent' might not have been initialized [Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized 运行时,突然中断,引起访问异常.提问:我该怎样初始化这些部件,是不是我机上少安装了什么东西?谢谢大虾!!!
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\filename.mdb;Persist Security Info=False
adocnnt.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False';
tbStudent.Connection:=adocnnt;
tbStudent.TableName:='student';
tbStudent.Active:=true;
tbStudent.open;
tbStudent.Insert;
tbStudent.InsertRecord([4,'小赵','男']);
tbStudent.Close;
但是,编译时出现如下错:
[Warning] Unit2.pas(40): Variable 'tbStudent' might not have been initialized
[Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized
[Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized
-->你是动态创建的?
如果可以,贴出完整的代码
var
tbStudent: TADOTable;
adocnnt: TADOConnection;
begin
adocnnt.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False';
tbStudent.Connection:=adocnnt;
tbStudent.TableName:='student';
tbStudent.Active:=true;
tbStudent.open;
tbStudent.Insert;
tbStudent.InsertRecord([4,'小赵','男']);
tbStudent.Close;
DBGrid1.Refresh;
end;
编译时出现如下警告错误:
[Warning] Unit2.pas(40): Variable 'tbStudent' might not have been initialized
[Warning] Unit2.pas(39): Variable 'adocnnt' might not have been initialized
运行时,突然中断,引起访问异常.提问:我该怎样初始化这些部件,是不是我机上少安装了什么东西?谢谢大虾!!!
tbStudent: TADOTable;
adocnnt: TADOConnection;
begin
adocnnt := TADOConnection.Create(nil);
tbStudent := TADOTable.Create(nil);
try
adocnnt.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample\test.mdb;Persist Security Info=False';
tbStudent.Connection:=adocnnt;
tbStudent.TableName:='student';
tbStudent.Active:=true;
tbStudent.open;
tbStudent.Insert;
tbStudent.InsertRecord([4,'小赵','男']);
tbStudent.Post;
tbStudent.Close;
DBGrid1.Refresh;
finally
tbStuent.Free;
adocnnt.Free;
end;
end;