我前台用了一个CreateUserWizard控件,Web.config配置文件中什么都没配。
这是我注册后台代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Web.Services.Description;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void CreateUserWizard1_CreatedUser1(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=" + Server.MapPath("App_Data//db1.mdb");
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;
comm.Parameters.AddWithValue("@UserName", ((TextBox)this.CreateUserWizardStep1.FindContro("UserName")).Text);
conn.Open();
int i = (int)comm.ExecuteScalar(); if (i > 0)
{ string UserNamee = ((TextBox)this.CreateUserWizard1.FindControl("UserName")).Text;
string UserPassword = ((TextBox)this.CreateUserWizard1.FindControl("Password")).Text;
string Conpassword = ((TextBox)this.CreateUserWizard1.FindControl("ConfirmPassword")).Text;
string Eail = ((TextBox)this.CreateUserWizard1.FindControl("Email")).Text;
string Question = ((TextBox)this.CreateUserWizard1.FindControl("Question")).Text;
string Answer = ((TextBox)this.CreateUserWizard1.FindControl("Answer")).Text;
comm.CommandText = "insert into zzg1(UserName,UserPassword,Conpassword,Eail,Question,Answer) values('" + UserNamee + "','" + UserPassword + "','" + Conpassword + "','" + Eail + "','" + Question + "','" + Answer + "')";
comm.ExecuteNonQuery();
}
else
{ Response.Write("<script>alert('sdasda')</script>"); } }
}调试了,可是为什么程序到了 comm.Parameters.AddWithValue("@UserName", ((TextBox)this.CreateUserWizardStep1.FindContro("UserName")).Text); 这,他老出未将对象引用设置到对象的实例的错误呀,弄了许多次都不行,到底是怎么回事呢 ?
这是我注册后台代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Web.Services.Description;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void CreateUserWizard1_CreatedUser1(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=" + Server.MapPath("App_Data//db1.mdb");
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;
comm.Parameters.AddWithValue("@UserName", ((TextBox)this.CreateUserWizardStep1.FindContro("UserName")).Text);
conn.Open();
int i = (int)comm.ExecuteScalar(); if (i > 0)
{ string UserNamee = ((TextBox)this.CreateUserWizard1.FindControl("UserName")).Text;
string UserPassword = ((TextBox)this.CreateUserWizard1.FindControl("Password")).Text;
string Conpassword = ((TextBox)this.CreateUserWizard1.FindControl("ConfirmPassword")).Text;
string Eail = ((TextBox)this.CreateUserWizard1.FindControl("Email")).Text;
string Question = ((TextBox)this.CreateUserWizard1.FindControl("Question")).Text;
string Answer = ((TextBox)this.CreateUserWizard1.FindControl("Answer")).Text;
comm.CommandText = "insert into zzg1(UserName,UserPassword,Conpassword,Eail,Question,Answer) values('" + UserNamee + "','" + UserPassword + "','" + Conpassword + "','" + Eail + "','" + Question + "','" + Answer + "')";
comm.ExecuteNonQuery();
}
else
{ Response.Write("<script>alert('sdasda')</script>"); } }
}调试了,可是为什么程序到了 comm.Parameters.AddWithValue("@UserName", ((TextBox)this.CreateUserWizardStep1.FindContro("UserName")).Text); 这,他老出未将对象引用设置到对象的实例的错误呀,弄了许多次都不行,到底是怎么回事呢 ?
解决方案 »
- Gridview 导出excel
- gridview模版列内如果动态添加图片控件,求教!
- gridview调用列数据问题!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 为什么没人回答我的问题????????????????????????????????????/
- 在文本框中,只能输入9位数,少一位都不行。要怎么解决?(要有验证控件)
- 请问多行文本框如何验证输入字符长度
- 用一句正则把图片src和style里的宽高取出来
- asp.net中如何实现边输入边加载
- 急,DATALIST控件中,每项绑定了两个dropdownlist,两个dropdownlist之间有联动,DATALIST中的项数是根据数据库数据动态变化,怎么写两个dropd
- DataGrid中就地编辑时如何让TextBox控件AutoPostBack时执行CS中的方法,解决立即结帖;
- Google地图&&ASP.NET,我迷茫了
- 小问题,解决就结贴——等待中
未将对象引用设置到对象的实例
很明显有用了 null 对象(TextBox)this.CreateUserWizardStep1.FindContro("UserName")) 是 null最好是:
TextBox txt = this.CreateUserWizardStep1.FindContro("UserName") as TextBox;
if(txt!=null){
//使用txt
}
if(txt!=null)
{
//代码
}
{
TextBox txt = this.CreateUserWizardStep1.FindContro("UserName") as TextBox;
}
catch
{}
空对象异常不处理 ,程序继续向下运行