注:表 student 各属性都是char类型 这是保存按钮的事件 try
{
DataRow dr = ds.Tables["student"].NewRow();
dr["sno"] = Int32.Parse(textBox1.Text);
dr["sname"] = Int32.Parse(textBox2.Text);
dr["ssex"] = Int32.Parse (textBox3.Text);
dr["sdept"] = Int32.Parse (textBox4.Text);
dr["dno"] = Int32.Parse (textBox5.Text);
dr["stime"] = Int32.Parse (textBox6.Text);
ds.Tables["student"].Rows.Add(dr);
da.Update(ds,"student");
this.BindingContext[ds, "student"].Position = this.BindingContext[ds, "student"].Count-1; }
catch (Exception ee) { MessageBox.Show("保存数据失败"+ee.Message ); }
}
{
DataRow dr = ds.Tables["student"].NewRow();
dr["sno"] = Int32.Parse(textBox1.Text);
dr["sname"] = Int32.Parse(textBox2.Text);
dr["ssex"] = Int32.Parse (textBox3.Text);
dr["sdept"] = Int32.Parse (textBox4.Text);
dr["dno"] = Int32.Parse (textBox5.Text);
dr["stime"] = Int32.Parse (textBox6.Text);
ds.Tables["student"].Rows.Add(dr);
da.Update(ds,"student");
this.BindingContext[ds, "student"].Position = this.BindingContext[ds, "student"].Count-1; }
catch (Exception ee) { MessageBox.Show("保存数据失败"+ee.Message ); }
}
你数据库本来就是char类型的就不用转了啊
直接这样写就好了:
dr["sno"] = textBox1.Text;还有为什么字段都是char的啊?你可以情况给不同的类型啊像地址什么的要是给char 有可能不够长啊,这样也会报错的。