我在筆記本電腦中創建了一個項目,並且工作正常。ASP.NET - System.NullReferenceException:未將對象引用設置爲對象的實例
我將我的項目轉移到另一臺筆記本電腦,現在它給了我一個System.NullReferenceException
錯誤。
不知何故,數據庫沒有建立,它給出了一個NULL異常。
我的代碼:
public partial class registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
// error is here
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["registerationConnectionString"].ConnectionString);
conn.Open();
string chekuser = "select count(*) from userdata where uname='" + TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(chekuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already Exist: ");
}
conn.Close();
}
}
}
WEB.CONFIG
<configuration>
<appSettings/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
</configuration>
拋出的異常在哪裏?您可能錯過了使用連接字符串的相應配置。 –
@DavidPine我不知道在哪裏。我對ASP.NET很陌生,對此我一無所知。你能告訴我一種設置數據庫連接的方法,以便我的其餘代碼可以正常工作嗎? – OBJ
我回答了問題 –