Access-Datenbank in Visual Studio 2008
-
Hallo,
ich bin totaler Anfänger in C++ - Programmierung und habe folgendes Problem:
Ich habe mit Visual Studio 2008 eine Reihe Forms angelegt, hab diese miteinander verbunden und habe jetzt das Problem, wie ich eine Access-Datenbank einbinde.
Über einige Forms muss ich etwas in die Datenbank eintragen, mit anderen etwas auslesen. Wie funktioniert das?Ich bin für jede Hilfe dankbar - sitze schon seit einer Woche an diesem Programm...
LG cam
-
Hab inzwischen etwas hier im Forum gefunden, stecke allerdings auch da fest. Und zwar geht es um das DataSet. Überall steht, dass man das über Project - Add New Item einfügt, aber da kann ich das nicht finden? Und wenn ich das DataSet über die Toolbox einfügen will, funktioniert das auch nicht richtig.
Ich bin echt am Verzweifeln! Hab schon so viele Leute gefragt und keiner kann mir weiterhelfen
-
wie öffnest du denn die datenbank? ADO?
du kannst daten direkt mit ner "INSERT INTO" anweisung an die datenbank senden.
zeig mal bischen code
-
Also ich kann die Datenbank noch gar nicht öffnen, weil ich absolut keine Ahnung habe, wie ich die einbinde
Hab schon alles mögliche probiert...
// ProfKeil.cpp : main project file. #include "stdafx.h" #include "Form1.h" using namespace ProfKeil; [STAThreadAttribute] int main(array<System::String ^> ^args) { // Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it Application::Run(gcnew Form1()); return 0; }
Hier soll dann mit der Artikelnummer ein neuer Datensatz angelegt werden:
#include "Box.h" #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace ProfKeil { /// <summary> /// Summary for Artikelnummer /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Artikelnummer : public System::Windows::Forms::Form { public: Artikelnummer(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Artikelnummer() { if (components) { delete components; } } private: System::Windows::Forms::Label^ ArtNr; private: System::Windows::Forms::TextBox^ txtArtNr; private: System::Windows::Forms::Button^ next; private: System::Windows::Forms::Button^ cancel; protected: protected: private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->ArtNr = (gcnew System::Windows::Forms::Label()); this->txtArtNr = (gcnew System::Windows::Forms::TextBox()); this->next = (gcnew System::Windows::Forms::Button()); this->cancel = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // ArtNr // this->ArtNr->AutoSize = true; this->ArtNr->Location = System::Drawing::Point(84, 73); this->ArtNr->Name = L"ArtNr"; this->ArtNr->Size = System::Drawing::Size(115, 13); this->ArtNr->TabIndex = 0; this->ArtNr->Text = L"Eingabe Artikelnummer"; this->ArtNr->TextAlign = System::Drawing::ContentAlignment::MiddleLeft; // // txtArtNr // this->txtArtNr->Location = System::Drawing::Point(84, 111); this->txtArtNr->Name = L"txtArtNr"; this->txtArtNr->Size = System::Drawing::Size(117, 20); this->txtArtNr->TabIndex = 1; // // next // this->next->Location = System::Drawing::Point(104, 229); this->next->Name = L"next"; this->next->Size = System::Drawing::Size(75, 23); this->next->TabIndex = 2; this->next->Text = L"Weiter"; this->next->UseVisualStyleBackColor = true; this->next->Click += gcnew System::EventHandler(this, &Artikelnummer::next_Click); // // cancel // this->cancel->Location = System::Drawing::Point(189, 229); this->cancel->Name = L"cancel"; this->cancel->Size = System::Drawing::Size(75, 23); this->cancel->TabIndex = 3; this->cancel->Text = L"Abbrechen"; this->cancel->UseVisualStyleBackColor = true; // // Artikelnummer // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(284, 264); this->Controls->Add(this->cancel); this->Controls->Add(this->next); this->Controls->Add(this->txtArtNr); this->Controls->Add(this->ArtNr); this->Name = L"Artikelnummer"; this->Text = L"Artikelnummer"; this->Load += gcnew System::EventHandler(this, &Artikelnummer::Artikelnummer_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void next_Click(System::Object^ sender, System::EventArgs^ e) { Box^ Artikelnummer = gcnew Box(); Artikelnummer->ShowDialog(); } private: System::Void Artikelnummer_Load(System::Object^ sender, System::EventArgs^ e) { } }; }
-
ok das ist c++/CLI oder;) damit kenn ich mich nicht aus, aber schau mal im netz nach ADO Datenbank mit CLI, da gibts sicher viel:)
hier ein kleiner ansporn;System::Data::OleDb::OleDbConnection dbCon("Connection-Strin"); System::Data::OleDb::OleDbCommand cmd("SELECT * FROM [Test]", %dbCon);