国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

詳細介紹asp.net 數據訪問層基類

2024-07-10 12:53:29
字體:
來源:轉載
供稿:網友

Asp.NET的多層體系結構主要解決數據層、邏輯層、表示層等之間的關系,這篇文章主要為大家詳細介紹asp.net 數據訪問層基類,具有一定的參考價值,感興趣的小伙伴們可以參考一下!

部分代碼:

復制代碼 代碼如下:

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 公用方法
///

/// 判斷是否存在某表的某個字段
///


///表名稱
///列名稱
/// 是否存在
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;
}
}
///


/// 表是否存在
///


///
///
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;
}
}
}

通過錯新技術頻道小編詳細介紹asp.net 數據訪問層基類,相信大家都有了一定的了解,如需了解更多的相關資訊,請繼續關注錯新技術頻道吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永胜县| 鹤庆县| 绵竹市| 瑞丽市| 乌兰县| 康乐县| 个旧市| 达日县| 商洛市| 深圳市| 河南省| 龙川县| 常熟市| 丹寨县| 浦江县| 江安县| 青龙| 呼伦贝尔市| 都兰县| 巴林右旗| 宣城市| 泸定县| 色达县| 文成县| 确山县| 顺昌县| 奎屯市| 杂多县| 无为县| 太仆寺旗| 县级市| 都昌县| 壤塘县| 竹北市| 屏山县| 太原市| 通化市| 新营市| 盐山县| 通化县| 昌江|