SqlHelper:带sqlParameter,对sql server增、册、查、改的公用方法
using System.Data;
using System.Data.SqlCient;
#region ###jonse
//共通函数 把sql语句执行的查询结果放入datatable中
// 传入sql语句,datatable名称,数据连接字符可选
public static DataTable GetDataTable(out string sEx, string sSql, string sDataTableName, string sConnStr = "", SqlParameter[] commandParameters = null)
{
sEx = string.Empty;
if (string.IsNullOrEmpty(sDataTableName))
{
sEx = "datatable的名字不能为空";
return null;
}
if (string.IsNullOrEmpty(sConnStr)) sConnStr = DbHelperSQL.connectionString;
DataTable dt = new DataTable();
try
{
if (commandParameters == null)
{
dt = ExecuteDataTable(sConnStr, CommandType.Text, sSql);
}
else
{
dt = ExecuteDataTable(sConnStr, CommandType.StoredProcedure, sSql, commandParameters);
}
}
catch (Exception ex)
{
sEx = ex.Message.ToString();
}
finally
{
dt.TableName = sDataTableName;
}
return dt;
}
// 取dataset
public static DataSet GetDataSet(out string sError, string sSQL, string sConnStr="")
相关新闻>>
- 发表评论
-
- 最新评论 更多>>