当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 数据访问层基类

asp.net 数据访问层基类

2017年12月12日  | 移动技术网IT编程  | 我要评论

枳组词,中国铁匠在异界,seo 报价

部分代码:

复制代码 代码如下:

using system;
using system.collections;
using system.collections.specialized;
using system.data;
using system.data.sqlclient;
using system.configuration;
using system.data.common;
using system.collections.generic;

namespace sosuo8.dbutility
{

public abstract class dbhelpersql
{
//数据库连接字符串

public static string connectionstring = configurationmanager.connectionstrings["conn"].tostring();


public static sqlconnection conn = new sqlconnection(connectionstring);
public dbhelpersql()
{
}

#region 公用方法
/// <summary>
/// 判断是否存在某表的某个字段
/// </summary>
/// <param name="tablename">表名称</param>
/// <param name="columnname">列名称</param>
/// <returns>是否存在</returns>
public static bool columnexists(string tablename, string columnname)
{
string sql = "select count(1) from syscolumns where [id]=object_id('" + tablename + "') and [name]='" + columnname + "'";
object res = getsingle(sql);
if (res == null)
{
return false;
}
return convert.toint32(res) > 0;
}
public static int getmaxid(string fieldname, string tablename,string wherestr)
{
string strsql = "select max(" + fieldname + ")+1 from " + tablename;
if (wherestr != string.empty)
{
strsql += " where " + wherestr;
}
object obj = dbhelpersql.getsingle(strsql);
if (obj == null)
{
return 1;
}
else
{
return int.parse(obj.tostring());
}
}
public static bool exists(string strsql)
{
object obj = dbhelpersql.getsingle(strsql);
int cmdresult;
if ((object.equals(obj, null)) || (object.equals(obj, system.dbnull.value)))
{
cmdresult = 0;
}
else
{
cmdresult = int.parse(obj.tostring());
}
if (cmdresult == 0)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 表是否存在
/// </summary>
/// <param name="tablename"></param>
/// <returns></returns>
public static bool tabexists(string tablename)
{
string strsql = "select count(*) from sysobjects where id = object_id(n'[" + tablename + "]') and objectproperty(id, n'isusertable') = 1";
//string strsql = "select count(*) from sys.objects where object_id = object_id(n'[dbo].[" + tablename + "]') and type in (n'u')";
object obj = dbhelpersql.getsingle(strsql);
int cmdresult;
if ((object.equals(obj, null)) || (object.equals(obj, system.dbnull.value)))
{
cmdresult = 0;
}
else
{
cmdresult = int.parse(obj.tostring());
}
if (cmdresult == 0)
{
return false;
}
else
{
return true;
}
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网