日期:2014-05-18  浏览次数:20468 次

高手给段代码:asp中用C#操作Access数据库的代码
包括连接数据库,添加、删除记录等示例代码。谢谢

------解决方案--------------------
用C#操作Access 就要写sql语句了,跟sql中一样的,就是没有存储过程,触发器之类的
------解决方案--------------------
我的一个插入:
if (!this.sfcf(hys,tjrq.Date, stime, etime))
{
s_sql = "INSERT INTO oo (rq,starttime,endtime,hys,job,dp,nm,pw,shb) VALUES ( ' " + tjrq + " ', ' " + stime + " ', ' " + etime + " ', ' " + hys + " ', ' " + md + " ', ' " + bm + " ', ' " + rm + " ', ' " + mm + " ', ' " + sb + " ') ";
OleDbConnection con = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=f:\\off\\off.mdb;User ID=;Password= ");
con.Open();
OleDbCommand cmd = new OleDbCommand(s_sql, con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
if (hys == "大会议室 ")
{
for (int gx = Convert.ToInt32(stm); gx <= etm; gx++)
{

OleDbCommand cmd1 = new OleDbCommand( "update sday5 set " + gxl[gx - 14] + "= 1 where eday = # " + tjrq.Date + "# ", con);

//OleDbCommand cmd1 = new OleDbCommand( "update sday3 set " + gxl[gx - 15] + "= 1 where eday = # " + tjrq.Date + "# ",con);
cmd1.ExecuteNonQuery();

}
con.Close();
Page.RegisterStartupScript( "key ", " <script> window.alert( '预约成功! ') </script> ");
string rqc;
rqc = Convert.ToString(tjrq.Date);

Response.Redirect( "hy_cx.aspx?id= " + rqc + " ");
}
else
{
for (int gx = Convert.ToInt32(stm); gx <= etm; gx++)
{

OleDbCommand cmd1 = new OleDbCommand( "update sday8 set " + gxl[gx - 14] + "= 1 where eday = # " + tjrq.Date + "# ", con);

//OleDbCommand cmd1 = new OleDbCommand( "update sday3 set " + gxl[gx - 15] + "= 1 where eday = # " + tjrq.Date + "# ",con);
cmd1.ExecuteNonQuery();
//con.Close();
}
con.Close();
Page.RegisterStartupScript( "key ", " <script> window.alert( '预约成功! ') </script> ");
string rqc;
rqc = Convert.ToString(tjrq.Date);
Response.Redirect( "hy_cx2.aspx?id= " + rqc + " ");
}

//this.Txt_md.Text = " ";
//this.Txt_md.Text = " ";
//this.Txt_yyr.Text = " ";
//this.Txt_bm.Text = " ";
//this.Txt_pass.Text = " ";

}
//con.Close();

}
else
{
Page.RegisterStartupScript( "key ", " <script> window.alert( '本时间段与其他预约有冲突!请重新选择。 ') </script> ");