C#窗体程序连接access数据库编写小型个人电脑程序时,需要编写相应的sql语句进行增删改查操作,因为access数据库的sql语句写法在某些方面和mysql存在较大的区别,本次着重对访问access数据库的sql语句进行讨论,并且实际已经运行通过。具体操作样式如下:
1.连接ACCESS2000数据库的语句
public static string strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_Client.mdb";
2.查询相应数据表中的记录总数
String sql = "select count(*) from tb_数据表";
3.查询该表中某一条记录的数值大于1的sql语句操作,注意中括号不能少
String sql = "select count(*) from tb_account where [数据表的具体某一栏]>=1";
4.查询某几个栏目的模糊查询语句,textBox1为下拉列表框
sql = "select [id],[account],[password],[name],[num],[time] from tb_account,tb_client where [_account_account]=[_client_account] and [name] like '%" + textBox1.Text + "%'";
5.计算某一栏 时间差与现在相比超过半年的记录
sql = "select * from tb_account, tb_client where [_account_account]=[_client_account] and DateDiff('d',[_client_time] ,now())>=183 and DateDiff('d',[_client_time] ,now())<365";