private void button2_Click(object sender, EventArgs e) //删除
{
string ConStr = string.Format(@"Provider=Microsoft.Jet.OLEdb.4.0;Data Source = {0}\yg606g_result.mdb",
Application.StartupPath);
OleDbConnection oleCon = new OleDbConnection(ConStr);
try
{
oleCon.Open();
OleDbCommand oleCmd = new OleDbCommand(ConStr, oleCon);
//oleCmd.Connection = oleCon;
oleCmd.CommandText = "DELETE FROM result where 次数 = '1'";
oleCmd.ExecuteNonQuery();
//OleDbDataAdapter oleDap = new OleDbDataAdapter("select * from Result", oleCon);
//DataSet ds = new DataSet();
//oleDap.Fill(ds, "result");
//this.dataGridView1.DataSource = ds.Tables["result"];//this method is good!
//this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(Convert.ToString(ex.Message));
}
oleCon.Close();
oleCon.Dispose();
}
private void button3_Click(object sender, EventArgs e) //添加
{
string ConStr = string.Format(@"Provider=Microsoft.Jet.OLEdb.4.0;Data Source = {0}\yg606g_result.mdb",
Application.StartupPath);
OleDbConnection oleCon = new OleDbConnection(ConStr);
//string ConStr1 = "Insert Into users(username) values('" & "小王" & "')";
try
{
oleCon.Open();
OleDbCommand oleCmd = new OleDbCommand(ConStr, oleCon);
//OleDbCommand oleCmd = new OleDbCommand();
//oleCmd.Connection = oleCon;
oleCmd.CommandText = "INsert into result VALUES('1','2015-08-3','0.067', '0.013','0.073','0.043','0.023','0.053')";
oleCmd.ExecuteNonQuery();
//OleDbDataAdapter oleDap = new OleDbDataAdapter("select * from Result", oleCon);
//DataSet ds = new DataSet();
//oleDap.Fill(ds, "result");
//this.dataGridView1.DataSource = ds.Tables["result"];//this method is good!
//this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(Convert.ToString(ex.Message));
}
oleCon.Close();
oleCon.Dispose();
}
private void button4_Click(object sender, EventArgs e) //修改某条记录
{
string ConStr = string.Format(@"Provider=Microsoft.Jet.OLEdb.4.0;Data Source = {0}\yg606g_result.mdb",
Application.StartupPath);
OleDbConnection oleCon = new OleDbConnection(ConStr);
try
{
oleCon.Open();
OleDbCommand oleCmd = new OleDbCommand(ConStr, oleCon);
//OleDbCommand oleCmd = new OleDbCommand();
//oleCmd.Connection = oleCon;
oleCmd.CommandText = "UPDATE result SET 热阻 = '13579' where 次数 = '1'";
oleCmd.ExecuteNonQuery();
//OleDbDataAdapter oleDap = new OleDbDataAdapter("select * from Result", oleCon);
//DataSet ds = new DataSet();
//oleDap.Fill(ds, "result");
//this.dataGridView1.DataSource = ds.Tables["result"];//this method is good!
//this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(Convert.ToString(ex.Message));
}
oleCon.Close();
oleCon.Dispose();
}
sql语句操作ACCESS,添加,更新,删除
最新推荐文章于 2021-12-30 16:00:29 发布