sql常用语句

时间:2016-04-05 19:40:04   收藏:0   阅读:1752

1、得到最大id      根据某个字段在某张表中

string strsql = "select max(" + FieldName + ")+1 from " + TableName;

2、是否存在该记录   根据id查找

StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) from tpwellbase0");
strSql.Append(" where ID=@ID");

3、增加一条数据     根据model增加

StringBuilder strSql=new StringBuilder();
strSql.Append("insert into tpwellbase0(");
strSql.Append("wellname,oil_pro_plant,block)");
strSql.Append(" values (");
strSql.Append("@wellname,@oil_pro_plant,@block)");

4、更新一条数据  根据model更新

StringBuilder strSql=new StringBuilder();
strSql.Append("update tpwellbase0 set ");
strSql.Append("wellname=@wellname,");
strSql.Append("oil_pro_plant=@oil_pro_plant,");
strSql.Append("block=@block");
strSql.Append(" where ID=@ID");

5、删除一条数据 根据id

StringBuilder strSql=new StringBuilder();
strSql.Append("delete from tpwellbase0 ");
strSql.Append(" where ID in ("+IDlist + ") ");

6、得到一个对象实体 根据id获取改行model

StringBuilder strSql=new StringBuilder();
strSql.Append("select ID,wellname,oil_pro_plant,block from tpwellbase0 ");
strSql.Append(" where ID=@ID");

7、获得数据列表list<model>

8、分页获取数据 dataset格式

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!