?? dataconnection.~cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DataConnection.h"
#include "main.h" //程序主窗體頭文件
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn1Click(TObject *Sender)
{ /*****確定按鈕單擊事件*****/
if(Form2->Edit1->Text.IsEmpty()) {
ShowMessage("輸入數據庫服務器名不能為空");
return;
}
Form2->Close(); //關閉窗體
//char dsname[100];
//StrCopy(dsname,"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student;Data Source=");
//StrCat(dsname,Form2->Edit1->Text.c_str()); //追加輸入的數據庫服務器名
String dsname;
dsname="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student;Data Source=";
dsname+=Form2->Edit1->Text;
Form1->ADOTable1->ConnectionString = dsname; //修改ADOTable的連接屬性
Form1->ADOTable2->ConnectionString = dsname;
Form1->ADOTable3->ConnectionString = dsname;
Form1->ADOTable4->ConnectionString = dsname;
Form1->ADOTable5->ConnectionString = dsname;
Form1->ADOT_Count->ConnectionString = dsname;
try //捕捉數據庫連接異常
{
Form1->ADOTable1->Active = true; //激活與數據庫的連接
Form1->ADOTable2->Active = true;
Form1->ADOTable3->Active = true;
Form1->ADOTable4->Active = true;
Form1->ADOTable5->Active = true;
Form1->ADOT_Count->Active = true;
}
catch(...)
{
Application->MessageBoxA("與數據庫服務器連接錯誤,確認輸入的服務器名","異常對話框",MB_OK);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn2Click(TObject *Sender)
{ /*****取消按鈕單擊事件*****/
Form2->Close(); //關閉窗體
Application->Terminate(); //中止程序運行
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Edit1KeyPress(TObject *Sender, char &Key)
{ /*****服務器名輸入框鍵盤輸入事件*****/
if(Key == VK_RETURN) //按下回車鍵執行
BitBtn1Click(this); //調用BitBtn1按鈕點擊事件
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -