没有数据啊!!!
怎么弄啊????
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=db/test.mdb";
string sql = "insert into info (姓名,性别,年龄) values('"+name.Text+"','"+sex.Text+"',"+age.Text+")";
if (name.Text.Trim() == "")
{
MessageBox.Show("姓名不能为空!!");
}
else
{
if (sex.Text.Trim() != "男" && sex.Text.Trim() != "女")
{
MessageBox.Show("性别必须是'男'或'女'!!");
sex.Text = "";
}
else
{
try
{
int ag=Convert.ToInt32(age.Text.Trim());
if (ag > 120 || ag < 0)
{
MessageBox.Show("年龄必须在1~120之间!!");
}
else
{
OleDbCommand odc = new OleDbCommand();
OleDbDataAdapter oda = new OleDbDataAdapter(sql,con);
DataSet ds = new DataSet();
con.Open();
oda.InsertCommand = odc;
odc.Connection = con;
odc.CommandText = sql;
int count = odc.ExecuteNonQuery();
odc.Dispose();
if (count > 0)
{
MessageBox.Show("添加成功!");
}
else
{
MessageBox.Show("添加失败!");
}
con.Close();
this.Close();
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString());
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
name.Text = "";
sex.Text = "";
age.Text = "";
}
}
}