问题出在SqlHelper的静态构造函数中
请问我该如何解决?步骤是什么样的?
sqlHelper在元数据里,
@博学多思: 建议检查一下web.config中是否配置了对应的连接字符串
@dudu:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="LocalTrafficConnectionString" connectionString="data source=172.31.132.5;User ID=readdba;Password=111aaa***;Initial Catalog=BDHChinaTraffic;Min Pool Size=20;Max Pool Size=75;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="Traffic3DCockpitImgURL" value="http://172.31.132.59:8003"/>
</appSettings>
</configuration>
@博学多思: 连接字符串没问题,建议用ILSpy看一下YYSSOFT.Lib2008.Systems.CommonHelper.SqlHelper的静态构造函数
@dudu: using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace YYSSOFT.Lib2008.Systems.CommonHelper
{
public abstract class SqlHelper
{
public static readonly string LocalTransactionConnectionString = ConfigurationManager.ConnectionStrings["LocalTransactionConnectionString"].ConnectionString;
public static readonly string LocalWorkFlowConnectionString = (ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"].ConnectionString;
public static readonly string LocalSMSConnectionString = (ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"].ConnectionString;
public static readonly string LocalTrafficConnectionString = (ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"].ConnectionString;
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters)
{
SqlHelper.parmCache[cacheKey] = commandParameters;
}
public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection);
SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters);
DataSet dataSet = new DataSet();
sqlDataAdapter.Fill(dataSet);
sqlDataAdapter.SelectCommand.Parameters.Clear();
return dataSet;
}
public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, string dataSetName, string tableName, params SqlParameter[] commandParameters)
{
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection);
SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters);
DataSet dataSet = new DataSet(dataSetName);
DataTable dataTable = new DataTable(tableName);
sqlDataAdapter.Fill(dataTable);
dataSet.Tables.Add(dataTable);
sqlDataAdapter.SelectCommand.Parameters.Clear();
return dataSet;
}
public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters);
int result = sqlCommand.ExecuteNonQuery();
sqlCommand.Parameters.Clear();
return result;
}
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters);
int result = sqlCommand.ExecuteNonQuery();
sqlCommand.Parameters.Clear();
return result;
}
public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
int result;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters);
int num = sqlCommand.ExecuteNonQuery();
sqlCommand.Parameters.Clear();
result = num;
}
return result;
}
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlDataReader result;
try
{
SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
sqlCommand.Parameters.Clear();
result = sqlDataReader;
}
catch
{
sqlConnection.Close();
throw;
}
return result;
}
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, out string[] returnParaValues, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlDataReader result;
try
{
SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
returnParaValues = SqlHelper.SetReturnParaValues(commandParameters);
sqlCommand.Parameters.Clear();
result = sqlDataReader;
}
catch
{
sqlConnection.Close();
throw;
}
return result;
}
public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters);
object result = sqlCommand.ExecuteScalar();
sqlCommand.Parameters.Clear();
return result;
}
public static object ExecuteScalar(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters);
object result = sqlCommand.ExecuteScalar();
sqlCommand.Parameters.Clear();
return result;
}
public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand sqlCommand = new SqlCommand();
object result;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters);
object obj = sqlCommand.ExecuteScalar();
sqlCommand.Parameters.Clear();
result = obj;
}
return result;
}
public static SqlParameter[] GetCachedParameters(string cacheKey)
{
SqlParameter[] array = (SqlParameter[])SqlHelper.parmCache[cacheKey];
SqlParameter[] result;
if (array == null)
{
result = null;
}
else
{
SqlParameter[] array2 = new SqlParameter[array.Length];
int i = 0;
int num = array.Length;
while (i < num)
{
array2[i] = (SqlParameter)((ICloneable)array[i]).Clone();
i++;
}
result = array2;
}
return result;
}
private static void PrepareCommand(SqlDataAdapter cmd, SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
cmd.SelectCommand.CommandType = cmdType;
if (cmdParms != null)
{
for (int i = 0; i < cmdParms.Length; i++)
{
SqlParameter value = cmdParms[i];
cmd.SelectCommand.Parameters.Add(value);
}
}
}
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
{
cmd.Transaction = trans;
}
cmd.CommandType = cmdType;
if (cmdParms != null)
{
for (int i = 0; i < cmdParms.Length; i++)
{
SqlParameter value = cmdParms[i];
cmd.Parameters.Add(value);
}
}
}
private static string[] SetReturnParaValues(params SqlParameter[] commandParameters)
{
string[] array = new string[0];
int i = 0;
int num = 0;
while (i < commandParameters.Length)
{
if (commandParameters[i].Direction == ParameterDirection.ReturnValue)
{
array[num] = commandParameters[i].Value.ToString();
num++;
}
i++;
}
return array;
}
}
}
@博学多思:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace YYSSOFT.Lib2008.Systems.CommonHelper { public abstract class SqlHelper { public static readonly string LocalTransactionConnectionString = ConfigurationManager.ConnectionStrings["LocalTransactionConnectionString"].ConnectionString; public static readonly string LocalWorkFlowConnectionString = (ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"].ConnectionString; public static readonly string LocalSMSConnectionString = (ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"].ConnectionString; public static readonly string LocalTrafficConnectionString = (ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"].ConnectionString; private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable()); public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters) { SqlHelper.parmCache[cacheKey] = commandParameters; } public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection); SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlDataAdapter.SelectCommand.Parameters.Clear(); return dataSet; } public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, string dataSetName, string tableName, params SqlParameter[] commandParameters) { SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection); SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters); DataSet dataSet = new DataSet(dataSetName); DataTable dataTable = new DataTable(tableName); sqlDataAdapter.Fill(dataTable); dataSet.Tables.Add(dataTable); sqlDataAdapter.SelectCommand.Parameters.Clear(); return dataSet; } public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters); int result = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); return result; } public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters); int result = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); return result; } public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); int result; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); int num = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); result = num; } return result; } public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataReader result; try { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); sqlCommand.Parameters.Clear(); result = sqlDataReader; } catch { sqlConnection.Close(); throw; } return result; } public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, out string[] returnParaValues, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataReader result; try { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); returnParaValues = SqlHelper.SetReturnParaValues(commandParameters); sqlCommand.Parameters.Clear(); result = sqlDataReader; } catch { sqlConnection.Close(); throw; } return result; } public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters); object result = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); return result; } public static object ExecuteScalar(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters); object result = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); return result; } public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); object result; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); object obj = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); result = obj; } return result; } public static SqlParameter[] GetCachedParameters(string cacheKey) { SqlParameter[] array = (SqlParameter[])SqlHelper.parmCache[cacheKey]; SqlParameter[] result; if (array == null) { result = null; } else { SqlParameter[] array2 = new SqlParameter[array.Length]; int i = 0; int num = array.Length; while (i < num) { array2[i] = (SqlParameter)((ICloneable)array[i]).Clone(); i++; } result = array2; } return result; } private static void PrepareCommand(SqlDataAdapter cmd, SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) { cmd.SelectCommand.CommandType = cmdType; if (cmdParms != null) { for (int i = 0; i < cmdParms.Length; i++) { SqlParameter value = cmdParms[i]; cmd.SelectCommand.Parameters.Add(value); } } } private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) { if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) { cmd.Transaction = trans; } cmd.CommandType = cmdType; if (cmdParms != null) { for (int i = 0; i < cmdParms.Length; i++) { SqlParameter value = cmdParms[i]; cmd.Parameters.Add(value); } } } private static string[] SetReturnParaValues(params SqlParameter[] commandParameters) { string[] array = new string[0]; int i = 0; int num = 0; while (i < commandParameters.Length) { if (commandParameters[i].Direction == ParameterDirection.ReturnValue) { array[num] = commandParameters[i].Value.ToString(); num++; } i++; } return array; } } }
@dudu: @博学多思:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace YYSSOFT.Lib2008.Systems.CommonHelper { public abstract class SqlHelper { public static readonly string LocalTransactionConnectionString = ConfigurationManager.ConnectionStrings["LocalTransactionConnectionString"].ConnectionString; public static readonly string LocalWorkFlowConnectionString = (ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalWorkFlowConnectionString"].ConnectionString; public static readonly string LocalSMSConnectionString = (ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalSMSConnectionString"].ConnectionString; public static readonly string LocalTrafficConnectionString = (ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"] == null) ? "" : ConfigurationManager.ConnectionStrings["LocalTrafficConnectionString"].ConnectionString; private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable()); public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters) { SqlHelper.parmCache[cacheKey] = commandParameters; } public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection); SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlDataAdapter.SelectCommand.Parameters.Clear(); return dataSet; } public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, string dataSetName, string tableName, params SqlParameter[] commandParameters) { SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdText, sqlConnection); SqlHelper.PrepareCommand(sqlDataAdapter, sqlConnection, cmdType, cmdText, commandParameters); DataSet dataSet = new DataSet(dataSetName); DataTable dataTable = new DataTable(tableName); sqlDataAdapter.Fill(dataTable); dataSet.Tables.Add(dataTable); sqlDataAdapter.SelectCommand.Parameters.Clear(); return dataSet; } public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters); int result = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); return result; } public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters); int result = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); return result; } public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); int result; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); int num = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); result = num; } return result; } public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataReader result; try { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); sqlCommand.Parameters.Clear(); result = sqlDataReader; } catch { sqlConnection.Close(); throw; } return result; } public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, out string[] returnParaValues, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlConnection sqlConnection = new SqlConnection(connectionString); SqlDataReader result; try { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); returnParaValues = SqlHelper.SetReturnParaValues(commandParameters); sqlCommand.Parameters.Clear(); result = sqlDataReader; } catch { sqlConnection.Close(); throw; } return result; } public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, connection, null, cmdType, cmdText, commandParameters); object result = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); return result; } public static object ExecuteScalar(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); SqlHelper.PrepareCommand(sqlCommand, trans.Connection, trans, cmdType, cmdText, commandParameters); object result = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); return result; } public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand sqlCommand = new SqlCommand(); object result; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlHelper.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, commandParameters); object obj = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); result = obj; } return result; } public static SqlParameter[] GetCachedParameters(string cacheKey) { SqlParameter[] array = (SqlParameter[])SqlHelper.parmCache[cacheKey]; SqlParameter[] result; if (array == null) { result = null; } else { SqlParameter[] array2 = new SqlParameter[array.Length]; int i = 0; int num = array.Length; while (i < num) { array2[i] = (SqlParameter)((ICloneable)array[i]).Clone(); i++; } result = array2; } return result; } private static void PrepareCommand(SqlDataAdapter cmd, SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) { cmd.SelectCommand.CommandType = cmdType; if (cmdParms != null) { for (int i = 0; i < cmdParms.Length; i++) { SqlParameter value = cmdParms[i]; cmd.SelectCommand.Parameters.Add(value); } } } private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) { if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) { cmd.Transaction = trans; } cmd.CommandType = cmdType; if (cmdParms != null) { for (int i = 0; i < cmdParms.Length; i++) { SqlParameter value = cmdParms[i]; cmd.Parameters.Add(value); } } } private static string[] SetReturnParaValues(params SqlParameter[] commandParameters) { string[] array = new string[0]; int i = 0; int num = 0; while (i < commandParameters.Length) { if (commandParameters[i].Direction == ParameterDirection.ReturnValue) { array[num] = commandParameters[i].Value.ToString(); num++; } i++; } return array; } } }
大侠,这个问题怎么解决?
@dudu:
SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.LocalTrafficConnectionString, CommandType.Text, sbSql.ToString(), parameters)
程序运到这里,SqlHelper.LocalTrafficConnectionString为空@!
@博学多思:
SqlHelper中读取的是LocalTransactionConnectionString连接字符串
public static readonly string LocalTransactionConnectionString = ConfigurationManager.ConnectionStrings["LocalTransactionConnectionString"].ConnectionString;
你在web.config中只配置了LocalTrafficConnectionString连接字符串。
@dudu: 请问我怎么能让SqlHelper读取LocalTrafficConnectionString连接字符串
@博学多思: web.config中LocalTrafficConnectionString的配置不动,再增加一个LocalTransactionConnectionString的配置,是没有配置LocalTransactionConnectionString连接字符串引起了“未将对象引用设置到对象的实例”。
@dudu: 我做的是团队项目,项目都是在vs上获取的!
@dudu: 问题已解决,十分感谢您的热情帮助!!
@dudu: @博学多思:
item.Cells[2].Text = GlobalCode.CommonDiction["WordLicenses"][((TC_TaxiCompanyInfo)item.DataItem).WordLicenses.ToString()].ToString();
GlobalCode.CommonDiction是个字典项集合,我想知道,它里面的值是怎么加进去的?什么时候加的??