1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace WindowsFormsApplication3
11 {
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18
19 DataSet ds = new DataSet();
20 DataTable TransInfo = new DataTable("TransInfo");
21 private void button1_Click(object sender, EventArgs e)
22 {
23 DataRow dr = TransInfo.NewRow();
24 dr["lotNo"] = textBox1.Text;
25 dr["carrierCode"] = textBox2.Text;
26 TransInfo.Rows.Add(dr);
27 //dataGridView1.DataSource = TransInfo; //表显示方式
28 dataGridView1.DataSource = ds.Tables[0]; //数据集合方式
29 //grid1.DataSource = TransInfo;
30 grid1.DataSource = ds.Tables[0];
31 }
32
33 private void Form1_Load(object sender, EventArgs e)
34 {
35 //类型 要窗体加载的时候启动 ,不然每次都会覆盖原来的
36 TransInfo.Columns.Add(new DataColumn("lotNo", typeof(string))); // typeof(string)) 上下两种类型写法
37 TransInfo.Columns.Add(new DataColumn("carrierCode", Type.GetType("System.String"))); // Type.GetType("System.String"))
38 ds.Tables.Add(TransInfo);
39 }
43 }
44 }
转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo
商业用途请与我联系:lcfhn168@163.com