Asp.net如何解决错误

kan*_*nan -1 asp.net

我正在设计我的网页,因为我输入了书籍ID并输入了Nameofthebook.然后单击该书的堆栈可用的按钮是转到另一页然后不可用显示错误消息是书不可用我的项目(库管理系统)

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Bookcheck : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string constr = null;
        constr = ConfigurationManager.ConnectionStrings["librarymanagementconnetionstring"].ConnectionString;
        SqlConnection cnn = new SqlConnection(constr);
        cnn.Open();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("SELECT*FROM BOOKREGISTRATIONDETAILS WHERE bookId='" + txtid.Text.Trim() + "'AND Nameofbook='" + txtnb.Text.Trim() + "'", constr);
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            Response.Redirect("Issueofbook.aspx");
        }
        else
        {
            Msg.Text = "NO book available";
            Msg.Visible = true;
        }
    }       
}      
Run Code Online (Sandbox Code Playgroud)

错误:
对象引用未设置为对象的实例.

dhi*_*chl 5

我注意到在librarymanagementconnetionstring中,连接拼写错误.这是您的web.config中连接字符串的正确条目吗?

  • 很好看,我错过了.经过反思,这可能比我的建议更有可能. (2认同)