ExecuteReader:连接错误消息
ExecuteReader: Connection error message
我想在文本框中显示数据,但 运行 我的 DAL 出现错误。我有一个存储过程,但我无法将我的数据获取到 return 值中的 return。我想用我的 BLL
到 return 一个数据表。你能帮忙吗?
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.
我正在使用如下所示的连接 class:
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);
}
}
}
看起来 DBCommand
的连接 属性 没有设置,在你 return 来自 Procedure
方法的命令之前你必须设置它的连接 属性:
DBCommand = DB.GetStoredProcCommand(procedure);
// DBCommand.Connection = ...
return DBCommand;
我想在文本框中显示数据,但 运行 我的 DAL 出现错误。我有一个存储过程,但我无法将我的数据获取到 return 值中的 return。我想用我的 BLL
到 return 一个数据表。你能帮忙吗?
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.
我正在使用如下所示的连接 class:
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);
}
}
}
看起来 DBCommand
的连接 属性 没有设置,在你 return 来自 Procedure
方法的命令之前你必须设置它的连接 属性:
DBCommand = DB.GetStoredProcCommand(procedure);
// DBCommand.Connection = ...
return DBCommand;