首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

高手给段代码:asp中用C#操作Access数据库的代码,该怎么解决

2012-01-08 
高手给段代码:asp中用C#操作Access数据库的代码包括连接数据库,添加、删除记录等示例代码。谢谢[解决办法]用

高手给段代码: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> ");
return;
}


}
public bool sfcf(String hys, DateTime rq, DateTime st, DateTime et)
{
OleDbConnection conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=f:\\off\\off.mdb;User ID=;Password= ");
conn.Open();
OleDbCommand cmd1 = new OleDbCommand( "select count(*) from oo where hys = ' "+hys+ " ' and rq = # " + rq.Date + "# and ((starttime <# " + et + "# and endtime > =# " + et + "#) or (starttime <=# " + st + "# and endtime > # " + st + "#) or (starttime <=# " + st + "# and endtime > =# " + et + "#)) ", conn);
int hs = 1;
//hs = cmd1.ExecuteNonQuery();
hs =Convert.ToInt32(cmd1.ExecuteScalar().ToString());
conn.Close();
OleDbConnection conn2 = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=f:\\off\\off.mdb;User ID=;Password= ");
conn2.Open();
OleDbCommand cmd2 = new OleDbCommand( "select count(*) from oo where hys = ' " + hys + " ' and rq =# " + rq.Date + "# ", conn2);
int kf = Convert.ToInt32(cmd2.ExecuteScalar().ToString());
conn2.Close();
if (kf == 0)
{
return false;
}
else
{
if (hs > 0)
{
return true;
}
else
{
return false;
}
}
}

[解决办法]
唉,这种问题能去先看看书吗

热点排行