Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jsksxs360 committed Nov 12, 2016
1 parent c16f140 commit 6294715
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Xus.SQLServerHelper/SQLServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void CloseConnection()
/// <returns>执行SQL语句受影响的行数</returns>
public int ExecuteSqlCommand(string sqlCommand, bool closeConnection = true)
{
if (sqlCommand == null || sqlCommand == string.Empty)
if (string.IsNullOrEmpty(sqlCommand))
throw new Exception("要执行的SQL语句不能为空");
OpenConnection();
SqlCommand sqlCmd = new SqlCommand(sqlCommand, SqlCnt);
Expand All @@ -132,7 +132,7 @@ public int ExecuteSqlCommand(string sqlCommand, bool closeConnection = true)
/// <returns>获取到的数据表</returns>
public DataTable GetTable(string selectSqlCommand)
{
if (selectSqlCommand == null || selectSqlCommand == string.Empty)
if (string.IsNullOrEmpty(selectSqlCommand))
throw new Exception("要执行的select语句不能为空");
OpenConnection();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectSqlCommand, SqlCnt);
Expand Down Expand Up @@ -160,7 +160,7 @@ public DataTable GetTable(string selectSqlCommand)
/// <returns>获取到的数据表</returns>
public DataTable GetTable(string tableName, int rows)
{
if (tableName == null || tableName == string.Empty)
if (string.IsNullOrEmpty(tableName))
throw new Exception("要获取的数据表名称不能为空");
OpenConnection();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select top " + rows + " * from " + tableName, SqlCnt);
Expand All @@ -185,7 +185,7 @@ public DataTable GetTable(string tableName, int rows)
/// <returns>SqlDataReader对象</returns>
public SqlDataReader GetDataStream(string selectSqlCommand)
{
if (selectSqlCommand == null || selectSqlCommand == string.Empty)
if (string.IsNullOrEmpty(selectSqlCommand))
throw new Exception("要执行的select语句不能为空");
OpenConnection();
SqlCommand sqlCmd = new SqlCommand(selectSqlCommand, SqlCnt);
Expand All @@ -211,9 +211,9 @@ public void AddDataToDataSet(DataSet dataSet, string selectSqlCommands, string i
{
if (dataSet == null)
throw new Exception("要填充数据的DataSet不能为null");
if (selectSqlCommands == null || selectSqlCommands == string.Empty)
if (string.IsNullOrEmpty(selectSqlCommands))
throw new Exception("获取数据的select语句不能为空");
if (insertTableName == null || insertTableName == string.Empty)
if (string.IsNullOrEmpty(insertTableName))
throw new Exception("插入的表名不能为空");
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectSqlCommands, SqlCnt);
try
Expand Down Expand Up @@ -282,7 +282,7 @@ public void UpdateTable(DataTable dataTable, string createTableSqlCommand)
{
if (dataTable == null)
throw new Exception("修改的数据表不能为空");
if (createTableSqlCommand == null || createTableSqlCommand == string.Empty)
if (string.IsNullOrEmpty(createTableSqlCommand))
throw new Exception("创建数据表的sql语句不能为空");
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(createTableSqlCommand, SqlCnt);
//为SqlDataAdapter赋予SqlCommandBuilder功能
Expand Down Expand Up @@ -310,7 +310,7 @@ public void UpdateTable(DataSet dataset, string TableName, string createTableSql
throw new Exception("修改过的DataSet不能为null");
if (TableName == null || TableName == string.Empty)
throw new Exception("数据表名不能为空");
if (createTableSqlCommand == null || createTableSqlCommand == string.Empty)
if (string.IsNullOrEmpty(createTableSqlCommand))
throw new Exception("创建数据表的select语句不能为空");
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(createTableSqlCommand, SqlCnt);
//为SqlDataAdapter赋予SqlCommandBuilder功能
Expand Down

0 comments on commit 6294715

Please sign in to comment.