Технология Microsoft ADO.NET


Программирование объектов ADO .NET - часть 5


public Form1() {

// // Required for Windows Form Designer support // InitializeComponent();

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(CommandText, ConnectionString); DataSet ds = new DataSet(); dataAdapter.Fill(ds, "Bezimyannaya"); dataGrid1.DataSource = ds.Tables["Bezimyannaya"].DefaultView; // // TODO: Add any constructor code after InitializeComponent call // }

/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }

Windows Form Designer generated code

/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }

private void Form1_Load(object sender, System.EventArgs e) {

} } }

Полный листинг программы - подключение к базе данных NorthwindCS:

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.SqlClient;

namespace ProgrammDataSQL { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dataGrid1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; string CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," + " PostalCode, Country, Phone, Fax FROM Customers"; string ConnectionString = "workstation id=7EA2B2F6068D473;packet size=4096;integrated security=SSPI;data sou" + "rce=\"(local)\";persist security info=False;initial catalog=NorthwindCS";

public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); SqlDataAdapter dataAdapter = new SqlDataAdapter(CommandText, ConnectionString); DataSet ds = new DataSet(); dataAdapter.Fill(ds, "Customer"); dataGrid1.DataSource = ds.Tables["Customer"].DefaultView;

// // TODO: Add any constructor code after InitializeComponent call // }

/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }

Windows Form Designer generated code

/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }

private void Form1_Load(object sender, System.EventArgs e) {

} } }




Начало  Назад  Вперед



Книжный магазин