DisconnectedApplication.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:2k
源码类别:
.net编程
开发平台:
Visual C++
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- #using <System.dll> // For Console I/O
- #using <System.Data.dll> // For ADO.NET
- #using <System.Xml.dll> // For serialization support in DataSet
- #using <System.Windows.Forms.dll> // For the form
- #using <System.Drawing.dll> // Also for the form
- using namespace System;
- using namespace System::Data; // Generic ADO.NET definitions, such as DataSet
- using namespace System::Data::SqlClient; // SQL Server data provider definitions
- using namespace System::ComponentModel; // .NET GUI classes
- using namespace System::Windows::Forms; // .NET forms
- // Form to display titles from the Pubs database
- __gc public class TitlesForm : public Form
- {
- public:
- TitlesForm()
- {
- // Set form properties
- this->Text = "Book titles from Pubs database";
- this->Size = System::Drawing::Size(310, 300);
- // Set Button properties
- btnFill = new Button();
- btnFill->Text = S"Fill";
- btnFill->Size = System::Drawing::Size(80, 25);
- btnFill->Location = System::Drawing::Point(210, 230);
- // Set DataGrid properties
- dgTitles = new DataGrid();
- dgTitles->Size = System::Drawing::Size(280, 200);
- dgTitles->Location = System::Drawing::Point(10, 10);
- // Add controls to form
- this->Controls->Add(btnFill);
- this->Controls->Add(dgTitles);
- // Set database-related information
- this->cnPubs = new SqlConnection(S"data source=(local);integrated security=true;initial catalog=Pubs");
- this->daTitles = new SqlDataAdapter(S"SELECT * FROM Titles", cnPubs);
- this->dsTitles = new DataSet("Titles");
- // Register button-click event handler
- this->btnFill->Click += new EventHandler(this, &TitlesForm::BtnFill_Clicked);
- }
- void BtnFill_Clicked(Object* pSender, EventArgs* pArgs)
- {
- this->daTitles->Fill(this->dsTitles);
- this->dgTitles->DataSource = this->dsTitles->Tables->Item[0]->DefaultView;
- }
- private:
- Button * btnFill;
- DataGrid * dgTitles;
- SqlConnection * cnPubs;
- SqlDataAdapter * daTitles;
- DataSet * dsTitles;
- };
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(void)
- #endif
- {
- // Create the form
- Application::Run(new TitlesForm());
- return 0;
- }