谁能帮小妹解决??高分求救,急,在线等

rxxsdd 2003-08-25 03:52:40
一个简单的BBS,我在登录页面输入了名称和密码,点击登录按钮弹出出错信息是:
Object reference not set to an instance of an object.是不是不能正常与数据库通信?数据库连接总是null,该怎么解决??谢谢!!!急!!!
...全文
32 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
alaisalaix 2003-08-26
  • 打赏
  • 举报
回复
可能出错的地方:
1。strConn=ConfigurationSettings.AppSettings["connectstring"];
原因:connectstring是否在web.config文件中存在而且正确,如下:
<appSettings>
<add key="connectstring" value="......"/>
</appSettings>

2。DataSet myDS=new DataSet();
myDS=myService.GetDS(strConnection,strConn);

首先myDS不必new,因为GetDS会返回一个DataSet实例
其次,检查一下你的webservice会不会出了问题,能不能正确返回一个DataSet
检查方法:直接访问web service,并设断点调试
dawave 2003-08-26
  • 打赏
  • 举报
回复
一般是数据库的连接没有建立起来,connection没有建起来,还是null,后面的dataset之类的对象引用他,就出现类似的错误信息。检查你得connectionstring,检查你的数据库。只要连接建立好了,一般就ok.
rxxsdd 2003-08-26
  • 打赏
  • 举报
回复
我用的SQL和win2000都是professional版的,会不会是问题所在?
谢谢各位!
diaopeng 2003-08-25
  • 打赏
  • 举报
回复
呵呵~~~~~未将引用设置到对象实例。是数据库连接问题,可能的原因有很多
feiyu21 2003-08-25
  • 打赏
  • 举报
回复
一個簡單的頁面﹐怎么搞得這么長。
goody9807 2003-08-25
  • 打赏
  • 举报
回复
up
zjjszw 2003-08-25
  • 打赏
  • 举报
回复
1﹐檢查你的connectstring寫對了沒有
2﹐檢查你的myService.GetDS(strConnection,strConn)連接上數據庫沒有
其他的語句先屏蔽掉。
panyee 2003-08-25
  • 打赏
  • 举报
回复
怎么是调用Web Service? 在myDS=myService.GetDS(strConnection,strConn);行作个断点跟踪一下, 看取得的两参数是否有值
kknew 2003-08-25
  • 打赏
  • 举报
回复
1,查看,数据库中的眸子段是否为NULL值
2,查看是否有对象被赋值为null;
rxxsdd 2003-08-25
  • 打赏
  • 举报
回复
源代码如下,谢谢!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Collections.Specialized;

namespace wsbbs1
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel PermitPanel;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox UserTextBox;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox PwdTextBox;
protected System.Web.UI.WebControls.Button LoginButton;
protected System.Web.UI.WebControls.Button RegisterButton;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label WelcomeLabel;
protected System.Web.UI.WebControls.LinkButton InLinkButton;
protected System.Web.UI.WebControls.LinkButton LogoutLinkButton;
protected System.Web.UI.WebControls.LinkButton PrefileLinkButton;
protected System.Web.UI.WebControls.LinkButton AdminLinkButton;
protected System.Web.UI.WebControls.Label ErrorLabel;
protected System.Web.UI.WebControls.LinkButton bbsadminLinkButton;
protected System.Web.UI.WebControls.LinkButton INLinkButton;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected wsbbs1.DataSet1 dataSet11;
protected System.Web.UI.WebControls.Panel LoginPanel;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSet11 = new wsbbs1.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
this.RegisterButton.Click += new System.EventHandler(this.RegisterButton_Click);
this.InLinkButton.Click += new System.EventHandler(this.InLinkButton_Click);
this.LogoutLinkButton.Click += new System.EventHandler(this.LogoutLinkButton_Click);
this.PrefileLinkButton.Click += new System.EventHandler(this.PrefileLinkButton_Click);
this.AdminLinkButton.Click += new System.EventHandler(this.AdminLinkButton_Click);
this.bbsadminLinkButton.Click += new System.EventHandler(this.LinkButton1_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Table", new System.Data.Common.DataColumnMapping[0])});
//this.sqlDataAdapter1.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler(this.sqlDataAdapter1_RowUpdated);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT FROM UserManager";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=DD;initial catalog=bbs;integrated security=SSPI;persist security info" +
"=False;workstation id=DD;packet size=4096";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}
#endregion

private void LoginButton_Click(object sender, System.EventArgs e)
{
localhost.Service1 myService;
myService=new localhost.Service1();
string strConn;
strConn=ConfigurationSettings.AppSettings["connectstring"];
string strConnection;
strConnection="select UserID,NickName,UPassWord,Purview from UserManager where NickName = "+"'"+ UserTextBox.Text+ "'";
DataSet myDS=new DataSet();
try
{
myDS=myService.GetDS(strConnection,strConn);
if (myDS.Tables[0].Rows.Count>0)
{
DataRow myDR=myDS.Tables[0].Rows[0];
if (PwdTextBox.Text==myDR["UPassWord"].ToString().Trim())
{
LoginPanel.Visible=false;
PermitPanel.Visible=true;
WelcomeLabel.Text="欢迎你的到来,"+UserTextBox.Text;
Session["UserID"]=myDR["UserID"].ToString().Trim();
if (myDR["Purview"].ToString().Trim()=="admin")
{
AdminLinkButton.Visible=true;
bbsadminLinkButton.Visible=true;
}
else
{
AdminLinkButton.Visible=false;
bbsadminLinkButton.Visible=false;
}
}
else
{
ErrorLabel.Text="密码错误,请重试或者重新注册";
ErrorLabel.Visible=true;
}
}
else
{
ErrorLabel.Text="你的用户名不存在,请重试或者重新注册";
ErrorLabel.Visible=true;
}
}
catch (Exception error)
{
Response.Write(error.Message.ToString());
}

}
acewang 2003-08-25
  • 打赏
  • 举报
回复
出错代码
zjjszw 2003-08-25
  • 打赏
  • 举报
回复
同意 declude() 看法
gweidian 2003-08-25
  • 打赏
  • 举报
回复
数据库链接有问题,如果开防火墙的话关掉它
declude 2003-08-25
  • 打赏
  • 举报
回复
语法错误,对象没有设置实例。
show your code: *.cs;

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧