asp.net 企业库 时ExecuteReader: Connection 属性尚未初始化
连接语句<connectionStrings><addname="ConnectionString"connectionString="Database=TeamDeyi...
连接语句<connectionStrings>
<add name="ConnectionString" connectionString="Database=TeamDeyi;Server=(local)\DB2005;uid=sa;pwd=sasa" providerName="System.Data.SqlClient" />
</connectionStrings> Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
using (DbDataReader reader = dbcommand.ExecuteReader())
{
if(reader.Read())
{
Response.Write("ss");
}
} 报错为ExecuteReader: Connection 属性尚未初始化。请问如何解决。 展开
<add name="ConnectionString" connectionString="Database=TeamDeyi;Server=(local)\DB2005;uid=sa;pwd=sasa" providerName="System.Data.SqlClient" />
</connectionStrings> Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
using (DbDataReader reader = dbcommand.ExecuteReader())
{
if(reader.Read())
{
Response.Write("ss");
}
} 报错为ExecuteReader: Connection 属性尚未初始化。请问如何解决。 展开
2个回答
2013-11-07
展开全部
Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
using (IDataReader reader = db.ExecuteReader(dbcommand))
{
if (reader.Read())
{
Console.Write("ss");
}
}或者 Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
dbcommand.Connection = db.CreateConnection();
dbcommand.Connection.Open();
using (DbDataReader reader = dbcommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
{
if (reader.Read())
{
Console.Write("ss");
}
}
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
using (IDataReader reader = db.ExecuteReader(dbcommand))
{
if (reader.Read())
{
Console.Write("ss");
}
}或者 Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbcommand = db.GetSqlStringCommand("SELECT * FROM PR_Admin");
dbcommand.Connection = db.CreateConnection();
dbcommand.Connection.Open();
using (DbDataReader reader = dbcommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
{
if (reader.Read())
{
Console.Write("ss");
}
}
2013-11-07
展开全部
要镇含添加string sqlstr = ConfigurationManager.ConnectionStrings["碰旅乱ConnectionString"笑档].ConnectionString;dbconnection conn=new dbconnenction(sqlstr);dbcommand.connection=conn;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询