private void btn_31_Click(object sender, System.EventArgs e)
{
#region 判断是否输入完整的信息
if(txt_name.Text=="" || txt_sex.Text=="" || txt_age.Text=="")
{
MessageBox.Show("请完整填写信息");
return;
}
#endregion
string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.MDB";
string strSQL="select * from [user]";
OleDbConnection conn=new OleDbConnection(strConn);
OleDbCommand cmd=new OleDbCommand(strSQL,conn);
try
{
conn.Open();
DataSet dataSet=new DataSet();
OleDbDataAdapter adapter=new OleDbDataAdapter(strSQL,conn);
adapter.Fill(dataSet);
DataTable table=new DataTable();
table=dataSet.Tables[0];
DataRow dr=table.NewRow();
dr["name"]=txt_name.Text;
dr["sex"]=txt_sex.Text;
dr["age"]=txt_age.Text;
table.Rows.Add(dr);
adapter.Update(dataSet);
MessageBox.Show("添加成功!\ndr[\"name\"]");
user_read(0);
}
catch(OleDbException oe)
{
MessageBox.Show(oe.ToString());
}
finally
{
if(conn.State==ConnectionState.Open)
{
conn.Close();
}
}
}
[此贴子已经被作者于2006-4-25 11:16:00编辑过]