日期:2014-05-17 浏览次数:21004 次
public partial class CPModel : Form
{
private DataSet myDS;
private OleDbConnection conn=null;
private OleDbDataAdapter da = null;
private void binddata()
{
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0.;Data Source=F:/CPDB.mdb");
conn.Open();
string sql = "select * from OriginData";
da = new OleDbDataAdapter(sql, conn);
myDS = new DataSet();
da.Fill(myDS,"OD");
this.dataGridView1.CurrentCellChanged -= new EventHandler(dataGridView1_CurrentCellChanged);
this.dataGridView1.DataSource = myDS.Tables["OD"].DefaultView;
this.dataGridView1.CurrentCellChanged += new EventHandler(dataGridView1_CurrentCellChanged);
this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.RowHeadersVisible = false;
}
public CPModel()
{
InitializeComponent();
binddata();
}
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
if (this.dataGridView1.CurrentRow.IsNewRow)
{
da.InsertCommand = conn.CreateCommand();
da.InsertCommand.CommandText = "insert into OriginData values(@Phases,@SpCode)";
da.InsertCommand.Parameters.Add("@Phases", OleDbType.VarChar, 10, "Phases");
da.InsertCommand.Parameters.Add("@Sp