1474 lines
60 KiB
C#
1474 lines
60 KiB
C#
using System;
|
||
//using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Collections;
|
||
using System.Collections.Specialized;
|
||
//using System.Data.OleDb;
|
||
|
||
//using SystemFramework;
|
||
//using BasicData;
|
||
using System.Text.RegularExpressions;
|
||
using BasicData;
|
||
using SystemFramework;
|
||
|
||
namespace DataLinkMesWork
|
||
{
|
||
|
||
/// <summary>
|
||
/// <20><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD>ࡪ<EFBFBD><E0A1AA><EFBFBD>ṩͨ<E1B9A9>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ʷ<EFBFBD><CAB7><EFBFBD>
|
||
/// </summary>
|
||
public partial class SQLCommon
|
||
{
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <param name="thisParms"></param>
|
||
/// <param name="isOutput"></param>
|
||
/// <returns></returns>
|
||
public static bool GetCmdParam(jsonobj json, ref SqlParameter[] thisParms,out bool isOutput )
|
||
{
|
||
//SqlParameter[] thisParms=null;
|
||
|
||
isOutput = false;
|
||
try
|
||
{
|
||
string[] parmas;
|
||
if (json.Param.Contains("\\&"))
|
||
{
|
||
parmas = Regex.Split(json.Param, "\\\\&", RegexOptions.IgnoreCase);
|
||
}
|
||
else
|
||
{
|
||
parmas = json.Param.Split('&');
|
||
}
|
||
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
for (int i = parmas.Length-1; i >= 0; i--) {
|
||
string a = parmas[i];
|
||
string illegal1 = "==";
|
||
string illegal2 = "null";
|
||
string illegal3 = "undefined";
|
||
if (a.IndexOf(illegal1) > -1 || a.IndexOf(illegal2) > -1 || a.IndexOf(illegal3) > -1) {
|
||
ArrayList ar = new ArrayList(parmas);
|
||
ar.Remove(parmas[i]);
|
||
parmas = (string[])ar.ToArray(typeof(string));
|
||
}
|
||
}
|
||
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD><C2B6><EFBFBD>thisParms<6D><73><EFBFBD><EFBFBD>
|
||
thisParms = new SqlParameter[parmas.Length];
|
||
for (int i = 0; i < parmas.Length; i++)
|
||
{
|
||
// <20><><EFBFBD>κ<EFBFBD> =
|
||
string[] pp;
|
||
if (parmas[i].Contains("\\="))
|
||
{
|
||
pp = Regex.Split(parmas[i], "\\\\=", RegexOptions.IgnoreCase);
|
||
}
|
||
else
|
||
{
|
||
pp = parmas[i].Split('=');
|
||
}
|
||
object inputValue = null;
|
||
if (pp.Length == 4)
|
||
{
|
||
if(pp[3]=="output")
|
||
{
|
||
inputValue = GetInputValue(pp);
|
||
thisParms[i] = new SqlParameter(pp[0], inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;
|
||
}
|
||
}
|
||
else if (pp.Length == 3)
|
||
{
|
||
inputValue = GetInputValue(pp);
|
||
|
||
thisParms[i] = new SqlParameter(pp[0], inputValue);
|
||
}
|
||
else if (pp.Length == 2)
|
||
{
|
||
thisParms[i] = new SqlParameter(pp[0], pp[1]);
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ex.ToString();
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Json<6F>ַ<EFBFBD><D6B7><EFBFBD>
|
||
/// </summary>
|
||
/// <param name="thisParms"></param>
|
||
/// <returns></returns>
|
||
public static string GetOutputValue(SqlParameter[] thisParms)
|
||
{
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
resultOutput = "";
|
||
int outputCount=0;
|
||
for (int i = 0; i < thisParms.Length; i++)
|
||
{
|
||
if (thisParms[i].Direction == ParameterDirection.Output)
|
||
{
|
||
if (outputCount == 0)
|
||
{
|
||
resultOutput = resultOutput + "\"" + thisParms[i].ParameterName + "\":" + "\"" + thisParms[i].Value.ToString() + "\"";
|
||
}
|
||
else
|
||
{
|
||
resultOutput = resultOutput + "," + "\"" + thisParms[i].ParameterName + "\":" + "\"" + thisParms[i].Value.ToString() + "\"";
|
||
}
|
||
outputCount++;
|
||
|
||
}
|
||
}
|
||
resultOutput = "[{" + resultOutput + "}]";
|
||
return resultOutput;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺŴ<CDBA><C5B4><EFBFBD>&1&Int|<7C><>λ<EFBFBD><CEBB>&ML050&String|PageCurrent&1&Int|PageSize&10&Int|PageCount&0&Int&Output|ItemCount&0&Int&Output
|
||
/// </summary>
|
||
/// <param name="pp"></param>
|
||
/// <returns></returns>
|
||
static object GetInputValue(string[] pp)
|
||
{
|
||
object inputValue = null;
|
||
switch (pp[2])
|
||
{
|
||
case "int":
|
||
inputValue = Convert.ToInt32(pp[1]);
|
||
break;
|
||
case "string":
|
||
inputValue = pp[1];
|
||
break;
|
||
case "boolean":
|
||
if(pp[1]=="1")
|
||
{
|
||
inputValue = true;
|
||
}
|
||
else
|
||
{
|
||
inputValue = false;
|
||
}
|
||
break;
|
||
case "datetime":
|
||
inputValue = Convert.ToDateTime(pp[1]);
|
||
break;
|
||
default:
|
||
inputValue = pp[1];
|
||
break;
|
||
}
|
||
|
||
return inputValue;
|
||
|
||
}
|
||
/// <summary>
|
||
/// SqlServer<65><72><EFBFBD><EFBFBD>״̬
|
||
/// =true <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// =false <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||
/// </summary>
|
||
static bool sqlServerConnectionStatus=true;
|
||
/// <summary>
|
||
/// SqlServer<65><72><EFBFBD><EFBFBD>״̬
|
||
/// =true <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// =false <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||
/// </summary>
|
||
public static bool SqlServerConnectionStatus
|
||
{
|
||
get
|
||
{
|
||
return sqlServerConnectionStatus;
|
||
}
|
||
set
|
||
{
|
||
sqlServerConnectionStatus = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
|
||
/// SqlServer<65><72><EFBFBD><EFBFBD>״̬
|
||
/// =true <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// =false <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static void TestConnection()
|
||
{
|
||
string sql = "select top 1 uid from sysusers ";
|
||
string connectionString = ApplicationConfig.ConnectionString_MES;
|
||
SqlConnection conn = new SqlConnection(connectionString);
|
||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||
try
|
||
{
|
||
conn.Open();
|
||
cmd.ExecuteNonQuery();
|
||
SqlServerConnectionStatus = true;
|
||
return;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
//SqlServerConnectionStatus = false;
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
// SqlServer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ״̬
|
||
return;
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
|
||
/// SqlServer<65><72><EFBFBD><EFBFBD>״̬
|
||
/// =true <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// =false <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool TestConnectionWorkStart()
|
||
{
|
||
bool isOK = true;
|
||
string sql = "select top 1 uid from sysusers ";
|
||
string connectionString = ApplicationConfig.ConnectionString_MES;
|
||
SqlConnection conn = new SqlConnection(connectionString);
|
||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||
try
|
||
{
|
||
conn.Open();
|
||
cmd.ExecuteNonQuery();
|
||
return isOK;
|
||
}
|
||
catch
|
||
{
|
||
isOK = false;
|
||
return isOK;
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// ִ<>б<EFBFBD>SQL<51><4C>䣬<EFBFBD><E4A3AC>Ҫ<EFBFBD>ؽ<F3B7B5BB><D8BD><EFBFBD><EFBFBD><EFBFBD>ʺϣ<CABA><CFA3><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ģ<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="sql"><3E><>SQL<51><4C><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
string sqlText="";
|
||
//SqlCommand cmd;
|
||
// using (SqlConnection connection =
|
||
//new SqlConnection(GetConnectionString()))
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlCommand cmd = new SqlCommand())
|
||
{
|
||
cmd.Connection = conn;
|
||
|
||
for (int i = 0; i < sql.Count; i++)
|
||
{
|
||
cmd.CommandText = sql[i].ToString();
|
||
sqlText = cmd.CommandText;
|
||
//SqlCommand cmd = new SqlCommand(sql[i].ToString(), conn);
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sqlText + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
return result;
|
||
}
|
||
//try
|
||
//{
|
||
// if (!SqlServerConnectionStatus) return false;
|
||
// conn.Open();
|
||
// cmd = new SqlCommand();
|
||
// cmd.Connection = conn;
|
||
|
||
// for (int i = 0; i < sql.Count; i++)
|
||
// {
|
||
// cmd.CommandText = sql[i].ToString();
|
||
// sqlText = cmd.CommandText;
|
||
// //SqlCommand cmd = new SqlCommand(sql[i].ToString(), conn);
|
||
// cmd.ExecuteNonQuery();
|
||
// }
|
||
// SqlServerConnectionStatus = true;
|
||
// result = true;
|
||
//}
|
||
//catch (Exception e)
|
||
//{
|
||
// errorMessage = e.ToString();
|
||
// TestConnection();
|
||
// ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sqlText + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
//}
|
||
//finally
|
||
//{
|
||
// if (conn.State == ConnectionState.Open)
|
||
// conn.Close();
|
||
//}
|
||
//return result;
|
||
}
|
||
/// <summary>
|
||
/// ִ<><D6B4>SQL<51><4C><EFBFBD>ʵ<EEA3AC><CAB5>Insert Update Delete <20><><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// ִ<><D6B4>SQL<51><EFBFBD><F3A3ACB7>ص<EFBFBD>һ<EFBFBD>У<EFBFBD><D0A3><EFBFBD>һ<EFBFBD>еĽ<D0B5><C4BD>
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="count"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
count = 0;
|
||
try
|
||
{
|
||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// ִ<>б<EFBFBD>SQL<51><4C>ѯ<EFBFBD><D1AF>䣬<EFBFBD><E4A3AC><EFBFBD>ؼ<EFBFBD>¼<EFBFBD><C2BC>
|
||
/// </summary>
|
||
/// <param name="sql"><3E><>SQL<51><4C>ѯ<EFBFBD><D1AF><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="ds"><3E><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
ds = new DataSet();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(sql, conn);
|
||
dsCommand.Fill(ds);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// ִ<>б<EFBFBD>SQL<51><4C>ѯ<EFBFBD><D1AF>䣬<EFBFBD><E4A3AC><EFBFBD>ؼ<EFBFBD>¼<EFBFBD><C2BC>
|
||
/// </summary>
|
||
/// <param name="sql"><3E><>SQL<51><4C>ѯ<EFBFBD><D1AF><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="dt"><3E><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(sql, conn);
|
||
dsCommand.Fill(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// ִ<>б<EFBFBD>SQL<51><4C>ѯ<EFBFBD><D1AF>䣬<EFBFBD><E4A3AC><EFBFBD>ؼ<EFBFBD>¼<EFBFBD><C2BC>
|
||
/// </summary>
|
||
/// <param name="sql"><3E><>SQL<51><4C>ѯ<EFBFBD><D1AF><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="dr"><3E><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
dr = null;
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
using (SqlCommand cmd = conn.CreateCommand())
|
||
{
|
||
cmd.CommandText = sql;
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ز<EFBFBD>ѯ<EFBFBD>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="sqlParameters"><3E>洢<EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="ds"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>淵<EFBFBD>صļ<D8B5>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, ref SqlParameter[] sqlParameters, out DataSet ds, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
ds = new DataSet();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
|
||
dsCommand.SelectCommand.CommandTimeout = 0;
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
|
||
dsCommand.Fill(ds);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, ref SqlParameter[] sqlParameters, out DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
//ds = new DataSet();
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
|
||
dsCommand.SelectCommand.CommandTimeout = 0;
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
|
||
dsCommand.Fill(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ز<EFBFBD>ѯ<EFBFBD>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="startRecord"><3E><><EFBFBD>俪ʼ<E4BFAA>Ĵ<EFBFBD><C4B4>㿪ʼ<E3BFAA>ļ<EFBFBD>¼<EFBFBD><C2BC></param>
|
||
/// <param name="maxRecords">Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC></param>
|
||
/// <param name="sqlParameters"><3E>洢<EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="ds"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>淵<EFBFBD>صļ<D8B5>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, int startRecord, int maxRecords, ref SqlParameter[] sqlParameters, out DataSet ds, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
ds = new DataSet();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
|
||
if(sqlParameters!=null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
dsCommand.Fill(ds, startRecord, maxRecords, "srcTable");
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ز<EFBFBD>ѯ<EFBFBD>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="sqlParameters"><3E>洢<EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, ref SqlParameter[] sqlParameters, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlCommand cmd = new SqlCommand(procedureName, conn))
|
||
{
|
||
cmd.CommandTimeout = 0;
|
||
cmd.CommandType = CommandType.StoredProcedure;
|
||
if(sqlParameters!=null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
cmd.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, ref SqlParameter[] sqlParameters,out long index, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
index = 0;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlCommand cmd = new SqlCommand(procedureName, conn))
|
||
{
|
||
cmd.CommandTimeout = 0;
|
||
cmd.CommandType = CommandType.StoredProcedure;
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
cmd.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
index = Convert.ToInt64( cmd.ExecuteScalar());
|
||
//cmd.ExecuteNonQuery();
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ز<EFBFBD>ѯ<EFBFBD>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
///
|
||
/// <param name="ds"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>淵<EFBFBD>صļ<D8B5>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, out DataSet ds, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
ds = new DataSet();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
|
||
|
||
dsCommand.Fill(ds);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ز<EFBFBD>ѯ<EFBFBD>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
///
|
||
/// <param name="dt"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>淵<EFBFBD>صļ<D8B5>¼<EFBFBD><C2BC></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, out DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
|
||
|
||
dsCommand.Fill(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Insert Delete Update 带参数的Sql语句 1001
|
||
/// 无返回值
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteInsertMesWork(string sql, ref SqlParameter[] sqlParameters, string connectionString,out string err)
|
||
{
|
||
bool result = false;
|
||
err = "OK"+ sql;
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
SqlCommand comm = new SqlCommand();
|
||
comm.Connection = conn;
|
||
comm.CommandText = sql;
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
comm.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
comm.ExecuteNonQuery();
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
err = e.ToString();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSqlMesWork\r\n" + sql + "\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Insert Delete Update 带参数的Sql语句 1001
|
||
/// 无返回值
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteInsertMesWork(string sql, ref SqlParameter[] sqlParameters, string connectionString,out long id,out string err)
|
||
{
|
||
bool result = false;
|
||
err = "OK"+sql;
|
||
id = -1;
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
SqlCommand comm = new SqlCommand();
|
||
comm.Connection = conn;
|
||
comm.CommandText = sql + " select @@IDENTITY ";
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
comm.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
id = Convert.ToInt64(comm.ExecuteScalar());
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
err = e.ToString();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSqlMesWork\r\n" + sql + "\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Insert Delete Update 带参数的Sql语句 1003
|
||
/// 无返回值
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteInsertMesWork(string sql, ref SqlParameter[] sqlParameters, string connectionString,out object index)
|
||
{
|
||
bool result = false;
|
||
index = -1;
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
SqlCommand comm = new SqlCommand();
|
||
comm.Connection = conn;
|
||
comm.CommandText = sql;
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
comm.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
index = comm.ExecuteScalar();
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSqlMesWork\r\n" + sql + "\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Select 带参数的Sql语句 1002
|
||
/// 无返回值
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="dt"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSelectMesWork(string sql, ref SqlParameter[] sqlParameters, string connectionString, out DataTable dt,out string err)
|
||
{
|
||
bool result = false;
|
||
err = "";
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter(sql, conn))
|
||
{
|
||
if(sqlParameters!=null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
dsCommand.Fill(dt);
|
||
}
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
err = e.ToString();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSelectMesWork\r\n" + sql + "\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 执行SQL语句,增、删、改,无返回
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 执行SQL语句,查询,返回表
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="dt"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.SelectCommand = new SqlCommand(sql, conn);
|
||
dsCommand.Fill(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 执行带参数的SQL语句,完成增、删、改
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSql(string sql, string connectionString, ref SqlParameter[] sqlParameters, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
cmd.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteNonQuery\r\nSQL\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// Select 带参数的Sql语句
|
||
/// 无返回值
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="dt"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSql(string sql, ref SqlParameter[] sqlParameters, string connectionString, out DataTable dt, out string err)
|
||
{
|
||
bool result = false;
|
||
err = "";
|
||
dt = new DataTable();
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter(sql, conn))
|
||
{
|
||
if (sqlParameters != null)
|
||
{
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.SelectCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
}
|
||
dsCommand.Fill(dt);
|
||
}
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
err = e.ToString();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSelectMesWork\r\n" + sql + "\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="sqlParameters"></param>
|
||
/// <param name="connectionString"></param>
|
||
/// <param name="dt"></param>
|
||
/// <param name="errorMessage"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteSQL(string sql, ref SqlParameter[] sqlParameters, string connectionString, DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
|
||
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.InsertCommand = new SqlCommand(sql, conn);
|
||
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
sqlParameters[i].IsNullable = true;
|
||
dsCommand.InsertCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
if (dt == null) return false;
|
||
dt.AcceptChanges();
|
||
for (int i = 0; i < dt.Rows.Count; i++)
|
||
{
|
||
dt.Rows[i].SetAdded();
|
||
}
|
||
dsCommand.Update(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
//ApplicationConfig.ConnectionStringPIS_NEW_Value = "0";
|
||
TestConnection();
|
||
errorMessage = e.ToString();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSQL\r\nSQL<51><4C>䣺\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݱ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ݿ<EFBFBD>ĵ<EFBFBD><C4B5>ã<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="sqlParameters"><3E>洢<EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="dt"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݱ<EFBFBD></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure(string procedureName, string connectionString, ref SqlParameter[] sqlParameters, DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.InsertCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.InsertCommand.CommandType = CommandType.StoredProcedure;
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.InsertCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
if (dt == null) return false;
|
||
dt.AcceptChanges();
|
||
for (int i = 0; i < dt.Rows.Count; i++)
|
||
{
|
||
dt.Rows[i].SetAdded();
|
||
}
|
||
dsCommand.Update(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static bool ExecuteSqlCmd(string sqlCmd, string connectionString, ref SqlParameter[] sqlParameters, DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
if (!SqlServerConnectionStatus) return false;
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.InsertCommand = new SqlCommand(sqlCmd, conn);
|
||
dsCommand.InsertCommand.CommandType = CommandType.Text;
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.InsertCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
if (dt == null) return false;
|
||
dt.AcceptChanges();
|
||
for (int i = 0; i < dt.Rows.Count; i++)
|
||
{
|
||
dt.Rows[i].SetAdded();
|
||
}
|
||
dsCommand.Update(dt);
|
||
}
|
||
SqlServerConnectionStatus = true;
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteSqlCmd\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + sqlCmd + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <20>ṩͨ<E1B9A9>õĵ<C3B5><C4B5>ô洢<C3B4><E6B4A2><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
||
/// </summary>
|
||
/// <param name="procedureName"><3E>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="connectionString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
||
/// <param name="sqlParameters"><3E>洢<EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||
/// <param name="dt"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݱ<EFBFBD></param>
|
||
/// <param name="errorMessage"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ</param>
|
||
/// <returns><3E><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>true<75><65>ʾ<EFBFBD><CABE>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD>false<73><65>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7></returns>
|
||
public static bool ExecuteStoredProcedure_Update(string procedureName, string connectionString, ref SqlParameter[] sqlParameters, DataTable dt, out string errorMessage)
|
||
{
|
||
bool result = false;
|
||
errorMessage = "";
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
conn.Open();
|
||
using (SqlDataAdapter dsCommand = new SqlDataAdapter())
|
||
{
|
||
dsCommand.UpdateCommand = new SqlCommand(procedureName, conn);
|
||
dsCommand.UpdateCommand.CommandType = CommandType.StoredProcedure;
|
||
for (int i = 0; i < sqlParameters.Length; i++)
|
||
{
|
||
dsCommand.UpdateCommand.Parameters.Add(sqlParameters[i]);
|
||
}
|
||
if (dt == null) return false;
|
||
dt.AcceptChanges();
|
||
for (int i = 0; i < dt.Rows.Count; i++)
|
||
{
|
||
dt.Rows[i].SetAdded();
|
||
}
|
||
dsCommand.Update(dt);
|
||
}
|
||
result = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
errorMessage = e.ToString();
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\nExecuteStoredProcedure\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + procedureName + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD>Ӽ<EFBFBD>¼<EFBFBD><EFBFBD><F3A3ACB7><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
/// <param name="newID"></param>
|
||
/// <returns></returns>
|
||
public static bool ExecuteNonQuery_newID(string sql, out long newID)
|
||
{
|
||
sql += ";select @@identity";
|
||
string connectionString;
|
||
connectionString = ApplicationConfig.ConnectionString_MES;
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||
{
|
||
conn.Open();
|
||
newID = Convert.ToInt64(cmd.ExecuteScalar());
|
||
}
|
||
return true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
newID = 0;
|
||
TestConnection();
|
||
ApplicationLog.WriteLog(e, "\r\n ExecuteNonQuery_newID\r\n<>洢<EFBFBD><E6B4A2><EFBFBD>̣<EFBFBD>\r\n" + sql + "\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>\r\n" + connectionString);
|
||
return false;
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
conn.Close();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|