使ACCESS数据库,适合初学者,修改连接、查询语句后可直接运行,代码中有注明。 填充DataSet的步骤 /**//// <summary> /**//// <summary> string source = @”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Manio\My Documents\PrintManager\program\PrintManageV1\DataBase\PrintDB.mdb”; /**///////////////////////////////// OleDbConnection OleCon = new OleDbConnection(source); OleDbDataAdapter da = new OleDbDataAdapter(select,OleCon); DataSet ds = new DataSet(); da.Fill(ds, “MainInfo”); dataGrid.SetDataBinding(ds, “MainInfo”); //DataGrid的数据绑定,使用DataSet 和 数据库的表名 /**//// <summary>
1、使用数据库连接字符串创建数据库连接对象
2、用SQL查询语句和数据库连接对象创建数据库适配器dataAdapter
3、使用DataAdapter的Fill 方法填充DataSet
using System;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
//Professional C# 2nd的DATAGRID实例
/**//// <summary>
/// This class provides an example of creating and using a data grid.
/// </summary>
public class DisplayTabularData : System.Windows.Forms.Form
{
private System.Windows.Forms.Button retrieveButton;
private System.Windows.Forms.DataGrid dataGrid;
/// Construct the window.
/// </summary>
/// <remarks>
/// This method constructs the window by creating both the data grid and the button.
/// </remarks>
public DisplayTabularData()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(464, 253);
this.Text = “01_DisplayTabularData”;
this.dataGrid = new System.Windows.Forms.DataGrid();
dataGrid.BeginInit();
dataGrid.Location = new System.Drawing.Point(8, 8);
dataGrid.Size = new System.Drawing.Size(448, 208);
dataGrid.TabIndex = 0;
dataGrid.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
this.Controls.Add(this.dataGrid);
dataGrid.EndInit();
this.retrieveButton = new System.Windows.Forms.Button();
retrieveButton.Location = new System.Drawing.Point(384, 224);
retrieveButton.Size = new System.Drawing.Size(75, 23);
retrieveButton.TabIndex = 1;
retrieveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
retrieveButton.Text = “Retrieve”;
retrieveButton.Click += new System.EventHandler(this.retrieveButton_Click);
this.Controls.Add(this.retrieveButton);
}
/// Retrieve the data
/// </summary>
/// <param name=”sender”> </param>
/// <param name=”e”> </param>
protected void retrieveButton_Click(object sender, System.EventArgs e)
{
retrieveButton.Enabled = false;
string select = “SELECT * FROM MainInfo”;
//填充DataSet的步骤
//1、使用数据库连接字符串创建数据库连接对象
// 2、用SQL查询语句和数据库连接对象创建数据库适配器dataAdapter
// 3、使用DataAdapter的Fill 方法填充DataSet
}
/// Display the application window
/// </summary>
static void Main()
{
Application.Run(new DisplayTabularData());
}
}
datagrid实例(简单易懂,无复杂功能,适合初学者) _asp.net技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » datagrid实例(简单易懂,无复杂功能,适合初学者) _asp.net技巧
相关推荐
-      对.net framework 反射的反思_asp.net技巧
-      .net3.5和vs2008中的asp.net ajax_asp.net技巧
-      使用asp.net ajax框架扩展html map控件_asp.net技巧
-      asp.net应用程序资源访问安全模型_asp.net技巧
-      photoshop初学者轻松绘制螺旋漩涡特效_photoshop教程
-      photoshop通道结合图层模式抠狗尾巴草_photoshop教程
-      web.config详解+asp.net优化_asp.net技巧
-      asp.net中多彩下拉框的实现_asp.net技巧