using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds = new DataSet();
DataTable TransInfo = new DataTable("TransInfo");
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = TransInfo.NewRow();
dr["lotNo"] = textBox1.Text;
dr["carrierCode"] = textBox2.Text;
TransInfo.Rows.Add(dr);
//dataGridView1.DataSource = TransInfo; //表显示方式
dataGridView1.DataSource = ds.Tables[]; //数据集合方式
//grid1.DataSource = TransInfo;
grid1.DataSource = ds.Tables[];
}
private void Form1_Load(object sender, EventArgs e)
{
//类型 要窗体加载的时候启动 ,不然每次都会覆盖原来的
TransInfo.Columns.Add(new DataColumn("lotNo", typeof(string))); // typeof(string)) 上下两种类型写法
TransInfo.Columns.Add(new DataColumn("carrierCode", Type.GetType("System.String"))); // Type.GetType("System.String"))
ds.Tables.Add(TransInfo);
}
}
}