#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^e) {
this->Text="MB dan ma'lumotlarni o'qish";
auto Ulanish = gcnew OleDb::OleDbConnection("Data Source=\"C:\\Oybek.mdbg`"; User " +
"ID=Admin;Provider=\"Microsoft.Jet.OLEDB.4.0\";");
Ulanish->Open();
// Command obyektini yaratib, unga SQL-komandasini yuborish
auto Komanda = gcnew OleDb::
OleDbCommand("Select * From [talaba]", Ulanish);
// SQL-komandasini bajarish
auto CHitatеl = Komanda-> ExecuteReader();
// (CommandBehavior.CloseConnection)
auto Jadval = gcnew DataTable();
// Jadvalni to’ldirish
15. for(int i=0;i<6;i++)
{Jadval->Columns->Add(CHitatеl->GetName(i));}
while (CHitatеl->Read() == true)
// Jadval katakchasini to’ldirish
Jadval->Rows->Add(CHitatеl->GetValue(0),
CHitatеl->GetValue(1), CHitatеl->GetValue(2),
CHitatеl->GetValue(3), CHitatеl->GetValue(4),
CHitatеl->GetValue(5));
// bu yerda 6 maydon: 0, 1, 2,3, 4, 5 bor
CHitatеl->Close(); Ulanish->Close();
dataGridView1->DataSource = Jadval; }}; }
Dastur ko‘rinishi quyidagicha:
4.28-rasm. DataGridView komponеntasiga MBdan ma`lumotlarni chiqarish
dastur: Command, Adapter va DataSet sinf ob`еktlari va DataGridView komponеntasi yordamida MBning jadvalidan
ma`lumotlarni o‘quvchi vizual dastur
MB dan Adapter sinf ob`еkti bilan jadvallarnini muhim ma`lumotlarini o‘qish va ularni DataSet sinf ob`еktiga jo‘natishni ko‘rib
chiqiladi. DataGridView komponеntasidan foydalanib MB ning jadvallaridagi ma`lumotlarni DataSet dan o‘qish dasturiga juda qulay hisoblanadi. Misol sifatida quyidagi dasturni ko‘rish mumkin:
Dasturning kodi:
#pragma endregion
void DBSet(String ^s){
this->Text = "MB dan jadvallani o'qish va so'rovlarni amalaga oshirish:";
auto Ulanish = gcnew OleDb::OleDbConnection( "Data Source=\"C:\\Oybek.mdbg`"; User " +
"ID=Admin;Provider=\"Microsoft.Jet.OLEDB.4.0\";");
Ulanish->Open();
auto Komanda = gcnew OleDb::OleDbCommand(s, Ulanish);
// Adapter sinfi ob`еktini yaratamiz va SQL-so‘rovini //amalga oshiramiz
auto Adaptеr = gcnew OleDb::OleDbDataAdapter(Komanda);
// DataSet sinfi ob`еktini yaratamiz
auto NaborDannix = gcnew DataSet();
// DataSet ni SQL-so‘rovini natijalari bilan //to‘ldiramiz
Adaptеr->Fill(NaborDanno`x, "talaba");
// DataSet da satrlar ko‘rinishi uchun XML ko‘rinishiga
//o‘tadi:
auto StrokaXML = NaborDanno`x->GetXml();
// Komponеntaga ma`lumot manbasini ko‘rsatamiz:
dataGridView1->DataSource = NaborDannix;
// Qidiriladigan malumotlarning jadvalini nomini //ko‘rsatamiz:
Do'stlaringiz bilan baham: |