//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "uDBPrint.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMainContent *frmMainContent;
//---------------------------------------------------------------------------
__fastcall TfrmMainContent::TfrmMainContent(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMainContent::btnExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMainContent::hlpAboutClick(TObject *Sender)
{
ShowMessage("没有任何异常处理,大家先将就着用.");
}
//---------------------------------------------------------------------------
void __fastcall TfrmMainContent::filExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMainContent::filOpenClick(TObject *Sender)
{
OpenDialog1->Execute();
//connDataBase
ADOConnection1->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+OpenDialog1->FileName+";Persist Security Info=False";
ADOConnection1->LoginPrompt =false;
ADOConnection1->Connected=true;
MemoData->Lines->Clear();
MemoData->Lines->Add("database:"+OpenDialog1->FileName);
ADOConnection1->GetTableNames(ListBox1->Items, false);
//ShowMessage(IntToStr(ListBox1->Items->Count));
MemoData->Lines->Add("");
MemoData->Lines->Add("tables");
for(int index=0;index<ListBox1->Items->Count;index++)
MemoData->Lines->Add(ListBox1->Items->Strings[index]);
for(int index=0;index<ListBox1->Items->Count;index++){
ADOTable1->TableName=ListBox1->Items->Strings[index];
ADOTable1->Open();
MemoData->Lines->Add("");
MemoData->Lines->Add(ADOTable1->TableName+" Fields");
for(int index2=0;index2<ADOTable1->FieldCount;index2++){
MemoData->Lines->Add(ADOTable1->Fields->Fields[index2]->FieldName+" "
+ADOTable1->Fields->Fields[index2]->DataType+" "
+ADOTable1->Fields->Fields[index2]->Size);
}
ADOTable1->Close();
}
ADOConnection1->Close();
ADOConnection1->ConnectionString="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmMainContent::ActionSaveToTextFileExecute(
TObject *Sender)
{
SaveDialog1->Execute();
MemoData->Lines->SaveToFile(SaveDialog1->FileName);
}
//---------------------------------------------------------------------------
表的定义被包含在TableDef集合中,调用GetTableDef
CListBox m_TableList;//在CFormView或对话框上添加的列表框
CFileDialog dlg(TRUE, "Open a Database File", "*.mdb");
if (dlg.DoModal() == IDOK && dlg.GetFileExt() == "mdb")
{
m_TableList.ResetContent();//清空列表框
CDaoDatabase db;
db.Open(dlg.GetPathName());
CDaoTableDefInfo info;
int nTables = db.GetTableDefCount();//总表数
for (int i = 0; i < nTables; i++)
{
db.GetTableDefInfo(i, info);//得到表的信息(结构体)
m_TableList.AddString(info.m_strName);//将表名添加到列表框
}
m_TableList.SetCurSel(0);//设置列表框的焦点为第一条选择
db.Close();
}
在C中可以```
VB就有點難叻```