using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace shujuwangge
{
public partial class Form1 : Form
{
//public DataTable emptable;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private DataTable createtable()
{
DataTable emptable = new DataTable("employee");
DataColumn col;
DataRow row;
//创建职员标记列,并添加到数据表中
col = new DataColumn();
col.DataType = System.Type.GetType("system.string");
col.ColumnName = "职员标识";
col.Caption = "职员标识";
col.ReadOnly = true;
col.Unique = true;
//将些列添加到datacolumncollection
emptable.Columns.Add(col);
//创建职员姓名列,并添加到表里边
col = new DataColumn();
col.DataType = System.Type.GetType("system.string");
col.ColumnName = "职员姓名";
col.Caption = "职员姓名";
col.ReadOnly = false;
col.Unique = false;
emptable.Columns.Add(col);
//创建地址列并且添加到表中
col = new DataColumn();
col.DataType = System.Type.GetType("system.string");
col.ColumnName = "职员地址";
col.Caption = "职员地址";
col.ReadOnly = false;
col.Unique = false;
emptable.Columns.Add(col);
col = new DataColumn();
col.DataType = System.Type.GetType("System.string");
col.ColumnName = "职员电话";
col.Caption = "职员电话";
col.ReadOnly = false;
col.Unique = false;
emptable.Columns.Add(col);
//创建三行,并交它们添加到表里边
row = emptable.NewRow();
row["职员标识"] = "001";
row["职员姓名"] = "王海";
row["职员地址"] = "枯树村";
row["职员电话"] = "5656";
emptable.Rows.Add(row);
row = emptable.NewRow();
row["职员标识"] = "002";
row["职员姓名"] = "王d海";
row["职员地址"] = "枯树村dfdfd";
row["职员电话"] = "5656df";
emptable.Rows.Add(row);
return emptable;
}
private void button1_Click(object sender, EventArgs e)
{
DataTable table = createtable();
dataGridView1.DataSource = table;
}
}
}