Part of the code:
Copy Code code as follows:
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
{
Database connection string
public static string connectionString = configurationmanager.connectionstrings["Conn"]. ToString ();
public static SqlConnection conn = new SqlConnection (connectionString);
Public Dbhelpersql ()
{
}
#region Common methods
<summary>
Determine if a field exists for a table
</summary>
<param name= "tablename" > table name </param>
<param name= "ColumnName" > Column name </param>
<returns> whether there is </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>
Whether the table exists
</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 ' IsU Sertable ') = 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;
}
}
}
Cloud-dwelling Community package download