源错误:
行 259: string str=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
行 260: SqlConnection cn=new SqlConnection(str);
行 261: cn.Open();
行 262: try
行 263: {
源文件: c:\inetpub\wwwroot\fzzp\index.aspx.cs 行: 261 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
LoadLibraryW(UInt16* ) +0
System.EnterpriseServices.Thunk.Security.Init() +76
System.EnterpriseServices.Thunk.Security.SuspendImpersonation() +81
System.EnterpriseServices.Platform.Initialize() +503
System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate cb) +11
System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl ctrl) +797
System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl ctrl) +170
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +358
System.Data.SqlClient.SqlConnection.Open() +384
FzZp.WebForm1.zhichangwenzai() in c:\inetpub\wwwroot\fzzp\index.aspx.cs:261
FzZp.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\fzzp\index.aspx.cs:107
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
下面附上代码```
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
this.zhichangwenzai();
this.zhichangwenzai1();
this.gengxinxinwen();
this.Qiye();
this.Qiye1();
}
``````
public void zhichangwenzai()
{
string str=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
SqlConnection cn=new SqlConnection(str);
cn.Open();
try
{
SqlCommand command=new SqlCommand("select * from job",cn);
SqlDataAdapter adapter=new SqlDataAdapter(command);
DataSet ds=new DataSet();
adapter.Fill(ds);
SqlDataReader dr;
dr=command.ExecuteReader();
````````````````
麻烦帮我看看,到底怎么改,。谢谢各位`
行 259: string str=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
行 260: SqlConnection cn=new SqlConnection(str);
行 261: cn.Open();
行 262: try
行 263: {
源文件: c:\inetpub\wwwroot\fzzp\index.aspx.cs 行: 261 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
LoadLibraryW(UInt16* ) +0
System.EnterpriseServices.Thunk.Security.Init() +76
System.EnterpriseServices.Thunk.Security.SuspendImpersonation() +81
System.EnterpriseServices.Platform.Initialize() +503
System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate cb) +11
System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl ctrl) +797
System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl ctrl) +170
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +358
System.Data.SqlClient.SqlConnection.Open() +384
FzZp.WebForm1.zhichangwenzai() in c:\inetpub\wwwroot\fzzp\index.aspx.cs:261
FzZp.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\fzzp\index.aspx.cs:107
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
下面附上代码```
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
this.zhichangwenzai();
this.zhichangwenzai1();
this.gengxinxinwen();
this.Qiye();
this.Qiye1();
}
``````
public void zhichangwenzai()
{
string str=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
SqlConnection cn=new SqlConnection(str);
cn.Open();
try
{
SqlCommand command=new SqlCommand("select * from job",cn);
SqlDataAdapter adapter=new SqlDataAdapter(command);
DataSet ds=new DataSet();
adapter.Fill(ds);
SqlDataReader dr;
dr=command.ExecuteReader();
````````````````
麻烦帮我看看,到底怎么改,。谢谢各位`
string str=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();这句取到连接字符串了吗?
注意是区分大小的哦!
这行是红色的,问题到底是数据库,还是代码呢?谢谢
错误 没有给数据集指定表名
应该用 DataSet DS =new DataSet("mytable");
adapter.Fill(ds);或者
adapter.Fill(ds,"mytable");
this.zhichangwenzai();是不是这句的问题,?
以及连接字符串是否正确
</appSettings>
web.config没问题`
adapter.Fill(ds);
错误 没有给数据集指定表名
应该用 DataSet DS =new DataSet("mytable");
adapter.Fill(ds);或者
adapter.Fill(ds,"mytable");
十分感谢,,,但问题依旧。
不指定表名使用默认名字
这个错误是没取到web.config文件里边的配置字符串
<add key="conn" value="server=(local);database=FzZp;uid=sa;pwd="/>
to:
<add key="conn" value="server=.;database=FzZp;uid=sa;pwd="/>
<add key="conn" value="server=(local);database=FzZp;uid=sa;pwd="/>
to:
<add key="conn" value="server=.;database=FzZp;uid=sa;pwd="/>
还是不行,跟踪调试了,看不出问题。。