我在本地没有问题。但我在上传的网站中收到此错误:
你调用的对象是空的。
在这个链接中,它说这是 ADO 的一个错误,但我没有在我的代码中使用 ADO。
这是我的代码:
SqlConnection sc = new SqlConnection();
sc.ConnectionString = MyConnectionString;
sc.Open();
SqlCommand scm = new SqlCommand(INSERT COMMAND);
scm.Connection = sc;
scm.ExecuteNonQuery();
sc.Close();
我把上面的代码放在USING
语句中,没有任何改变。
这是我的堆栈跟踪
NullReferenceException:对象引用未设置为对象的实例。]
Register.BtnRegister_Click(Object sender, ImageClickEventArgs e) +601
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
System.Web.UI.WebControls .ImageButton.RaisePostBackEvent(String eventArgument) +120System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page .RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +5563
这是BtnRegister_Click
代码:
protected void BtnRegister_Click(object sender, ImageClickEventArgs e)
{
if (TxtName.Text == "" || TxtFamily.Text == "" || txtNationalCode.Text == "" || TxtIdNumber.Text == "" || txtMobile.Text == "" || TxtEmail.Text == "" || txtAddress.Text == "" || TxtSecurityCode.Text == "")
{
LblMsg.Text = "You should fill all fields";
return;
}
if (txtNationalCode.Text.Length != 10)
{
LblMsg.Text = "National code must have 10 digits";
return;
}
if (txtMobile.Text.Length != 11)
{
LblMsg.Text = "Mobile number should have 11 digits";
return;
}
if (T_Paticipant.GetDataByNationalCode(txtNationalCode.Text).Rows.Count > 0)
{
LblMsg.Text = "This national code used before";
return;
}
if (T_Paticipant.GetDataByEmail(TxtEmail.Text).Rows.Count > 0)
{
LblMsg.Text = "This email used before";
return;
}
LblMessage.Text = "Are you sure to register?";
LblFlag.Text = "0";
//captcha
if (this.Session["CaptchaImageText"].ToString().ToLower() == TxtSecurityCode.Text.ToLower())
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "showMessage()", "<script>ShowMessage() </script>");
}
else
{
LblMsg.ForeColor = System.Drawing.Color.Red;
LblMsg.Text = "Security code is wrong";
}
//end captcha
}
谢谢你的帮助。