level 3
雁翎77
楼主
}
public static SqlCommand CreateCommand()
{
string connectionString = @"server=(local)\SQLEXPRESS;database=XiZai;user=xiazai;password=123";
// string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
//string connectionString = @"Server=202.118.83.35;user=safedown10;password=safedown10; Database=safedown10";
SqlConnection con = new SqlConnection(connectionString); // SqlConnection con= new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con; return cmd;
} public static int ExecuteNonQuery(SqlCommand command, SqlParameter[] cmdParms) //返回影响行数
{
int affectedRows = -1;
// string errortext;
try
{
command.Connection.Open();
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
if (parm != null)
command.Parameters.Add(parm);
}
affectedRows = command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;// }
finally { command.Connection.Close(); }
return affectedRows;
}
public static DataTable ExcuteSelectCommand(SqlCommand command, SqlParameter[] cmdParms) //返回一个表
{
DataTable table;
try
{
command.Connection.Open();
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
if (parm != null)
command.Parameters.Add(parm);
}
SqlDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
reader.Close();
}
catch (Exception ex)
{
throw ex;
//这里出错,请问如何解决,谢谢。
}
finally
{
command.Connection.Close();
}
return table;
}
}
2013年03月28日 10点03分
1
public static SqlCommand CreateCommand()
{
string connectionString = @"server=(local)\SQLEXPRESS;database=XiZai;user=xiazai;password=123";
// string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
//string connectionString = @"Server=202.118.83.35;user=safedown10;password=safedown10; Database=safedown10";
SqlConnection con = new SqlConnection(connectionString); // SqlConnection con= new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con; return cmd;
} public static int ExecuteNonQuery(SqlCommand command, SqlParameter[] cmdParms) //返回影响行数
{
int affectedRows = -1;
// string errortext;
try
{
command.Connection.Open();
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
if (parm != null)
command.Parameters.Add(parm);
}
affectedRows = command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;// }
finally { command.Connection.Close(); }
return affectedRows;
}
public static DataTable ExcuteSelectCommand(SqlCommand command, SqlParameter[] cmdParms) //返回一个表
{
DataTable table;
try
{
command.Connection.Open();
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
if (parm != null)
command.Parameters.Add(parm);
}
SqlDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
command.Connection.Close();
}
return table;
}
}