Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Data. SqlClient;
Using System. Collections;
Using System. Data;
Using System. Configuration;
Using System. Web;
/// <Summary>
/// Summary of SqlHelper
/// </Summary>
Public class SqlHelper
{
Private static readonly string connectionString = ConfigurationManager. ConnectionStrings ["DataBaseString"]. ConnectionString;
Public SqlHelper ()
{
}
# Region Public Method
Public static int GetMaxID (string FieldName, string TableName)
{
String strsql = "select max (" + FieldName + ") + 1 from" + TableName;
Object obj = SqlHelper. GetSingle (strsql );
If (obj = null)
{
Return 1;
}
Else
{
Return int. Parse (obj. ToString ());
}
}
Public static bool Exists (string strSql)
{
Object obj = SqlHelper. 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 Exists (string strSql, params SqlParameter [] partition parms)
{
Object obj = SqlHelper. GetSingle (strSql, limit parms );
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;
}
}
# Endregion
# Region execute simple SQL statements
/// <Summary>
/// Execute the SQL statement and return the number of affected records
/// </Summary>
/// <Param name = "SQLString"> SQL statement </param>
/// <Returns> Number of affected records </returns>
Public static int ExecuteSql (string SQLString)
{
Using (SqlConnection connection = new SqlConnection (connectionString ))
{
Using (SqlCommand cmd = new SqlCommand (SQLString, connection ))
{
Try
{
Connection. Open ();
Int rows = cmd. ExecuteNonQuery ();
Return rows;
}
Catch (System. Data. SqlClient. SqlException E)
{
Connection. Close ();
Throw new Exception (E. Message );
}
}
}
}
/// <Summary>