im designing my web page, in that i have typed in the book id and typed Nameofthebook. and then click the button the stack of book are available is go to another page and then not available is display the error message is book is not available My project (Library management system)
using System;
using System.Collections;
us开发者_JS百科ing 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"].ConnectionStrin
g
;
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;
}
}
}
}
My error
NULL reference exception in un handle by the user
constr =
ConfigurationManager.ConnectionStrings["librarymanagementconnetionstring"].ConnectionStrin
g;
Verify that the config file that you use has a connection string defined with the name librarymanagementconnetionstring
. I think it does not have that, which makes ConfigurationManager.ConnectionStrings["librarymanagementconnetionstring"]
return null
, causing a NullReferenceException
when you try to access the ConnectionString
property.
It should look something like this:
<configuration>
<connectionStrings>
<add
name="librarymanagementconnetionstring"
connectionString="[connection string goes here]"/>
</connectionStrings>
</configuration>
Looks like you are referring with an incorrect connection string key librarymanagementconnetionstring
.
精彩评论