110,545
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 连接数据库
/// </summary>
/// <returns></returns>
public bool ConnectionDatabase()
{
if (!isConnected)
{
try
{
if (connection == null)
{
connString = ConfigurationManager.ConnectionStrings["TerminalFixtureDB"].ToString();
connection = new SqlConnection(connString);
connection.Open();
}
if (command == null)
{
command = new SqlCommand();
}
command.Connection = connection;
}
catch
{
isConnected = false;
return false;
}
}
isConnected = true;
return true;
}
/// <summary>
/// 返回DataReader
/// </summary>
/// <param name="sqlOrProcedureName">Sql语句或者存储过程名</param>
/// <param name="isProcedure">是否存储过程,存储过程(true)</param>
public SqlDataReader GetReader(string sqlOrProcedureName, bool isProcedure)
{
if (ConnectionDatabase())
{
if (isProcedure)
command.CommandType = CommandType.StoredProcedure;
else
command.CommandText = sqlOrProcedureName;
}
return command.ExecuteReader();
}