-1
我想在我的文本框中顯示數據,並且在我的DAL中遇到錯誤。我有一個存儲過程,但我無法讓我的數據返回返回值。我想用我的BLL
返回一個DataTable。請你幫忙嗎?ExecuteReader:連接錯誤消息
DAL
public static string GetTicket(collection b)
{
try
{
string returnValue = string.Empty;
DB = Connect();
DBCommand = connection.Procedure("getTicket");
DB.AddInParameter(DBCommand, "@SupportRef", DbType.String, b.SupportRef1);
var myReader = DBCommand.ExecuteReader();
while (myReader.Read())
{
returnValue = myReader.GetString(0);
}
return returnValue;
}
catch (Exception ex)
{
throw ex;
}
}
我收到以下錯誤:
ExecuteReader: Connection property has not been initialized.
我使用的連接類,看起來像這樣:
public class connection
{
const string StrConnection = "TicketHelperConnectionString";
internal static Database DB;
public static DbCommand DBCommand;
public static Database Connect()
{
try
{
DB = DatabaseFactory.CreateDatabase(StrConnection);
return DB;
}
catch (Exception ex)
{
throw (ex);
}
}
public static DbCommand Procedure(string procedure)
{
try
{
DBCommand = DB.GetStoredProcCommand(procedure);
return DBCommand;
}
catch (Exception ex)
{
throw (ex);
}
}
}