DataTable 加载表结构
DataTable dt1 = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
dt1.Columns.Add("物料编号", typeof(string));
dt1.Columns.Add("物料名称", typeof(string));
dt1.Columns.Add("需求数量", typeof(string));
dt1.Columns.Add("物料来源", typeof(string));
dt1.Columns.Add("单位", typeof(string));
}
foreach (DataRow dr in dt1.Rows)
{
if (dr["物料编号"].ToString().Trim() == textBox5.Text.ToString().Trim())
{
MessageBox.Show("此物料已经新增");
textBox5.Text = "";
textBox7.Text = "";
textBox5.Focus();
return;
}
}
dt1.Rows.Add(textBox5.Text.ToString().ToUpper().Trim(), textBox6.Text.Trim(), textBox7.Text.Trim(), textBox8.Text.Trim(), textBox9.Text.Trim());