private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection myconnection=new SqlConnection(stringconnection);
SqlCommand comm=myconnection.CreateCommand();
comm.CommandText="select * from denglu where username=@username ";
SqlDataAdapter mycommand=new SqlDataAdapter(comm);
mycommand.SelectCommand.Parameters.Add(new SqlParamete("@username",SqlDbType.VarChar,10));
mycommand.SelectCommand.Parameters["@username"].Value=this.TextBox1.Text;
DataSet dr=new DataSet();
try
{
myconnection.Open();
mycommand.Fill(dr,"sss");
}
catch(Exception ee)
{
this.TextBox1.Text=ee.Message;
Response.Write("ee="+ee.Message);
}
finally
{
myconnection.Close();
}
return;
String insertMd="insert into denglu(username,password,power)values(@username,@password,@power)";
SqlCommand Cmd=new SqlCommand(insertMd,myconnection);
Cmd.Parameters.Add(new SqlParameter("@username",SqlDbType.VarChar,10));
Cmd.Parameters["@username"].Value=this.TextBox1.Text;
Cmd.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,10));
Cmd.Parameters["@password"].Value=this.TextBox2.Text;
Cmd.Parameters.Add(new SqlParameter("@power",SqlDbType.Bit));
if(this.DropDownList1.SelectedIndex==0)
{
Cmd.Parameters["@power"].Value=true;
}
else
{
Cmd.Parameters["@power"].Value=false;
}
Cmd.Connection.Open();
try
{
if (dr.Tables["denglu"].Rows[0]["username"].ToString()!=this.TextBox1.Text)
{
if( this.TextBox2.Text==this.TextBox3.Text)
{
Cmd.ExecuteNonQuery();
Response.Write("录入成功");
myconnection.Close();
}
else
{
Response.Write("2次输入密码不相同");
}
}
else
{
Response.Write("用户已存在");
}
}
catch(Exception ee)
{
Response.Write(ee.Message);
}
} }
}
{
SqlConnection myconnection=new SqlConnection(stringconnection);
SqlCommand comm=myconnection.CreateCommand();
comm.CommandText="select * from denglu where username=@username ";
SqlDataAdapter mycommand=new SqlDataAdapter(comm);
mycommand.SelectCommand.Parameters.Add(new SqlParamete("@username",SqlDbType.VarChar,10));
mycommand.SelectCommand.Parameters["@username"].Value=this.TextBox1.Text;
DataSet dr=new DataSet();
try
{
myconnection.Open();
mycommand.Fill(dr,"sss");
}
catch(Exception ee)
{
this.TextBox1.Text=ee.Message;
Response.Write("ee="+ee.Message);
}
finally
{
myconnection.Close();
}
return;
String insertMd="insert into denglu(username,password,power)values(@username,@password,@power)";
SqlCommand Cmd=new SqlCommand(insertMd,myconnection);
Cmd.Parameters.Add(new SqlParameter("@username",SqlDbType.VarChar,10));
Cmd.Parameters["@username"].Value=this.TextBox1.Text;
Cmd.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,10));
Cmd.Parameters["@password"].Value=this.TextBox2.Text;
Cmd.Parameters.Add(new SqlParameter("@power",SqlDbType.Bit));
if(this.DropDownList1.SelectedIndex==0)
{
Cmd.Parameters["@power"].Value=true;
}
else
{
Cmd.Parameters["@power"].Value=false;
}
Cmd.Connection.Open();
try
{
if (dr.Tables["denglu"].Rows[0]["username"].ToString()!=this.TextBox1.Text)
{
if( this.TextBox2.Text==this.TextBox3.Text)
{
Cmd.ExecuteNonQuery();
Response.Write("录入成功");
myconnection.Close();
}
else
{
Response.Write("2次输入密码不相同");
}
}
else
{
Response.Write("用户已存在");
}
}
catch(Exception ee)
{
Response.Write(ee.Message);
}
} }
}
{
myconnection.Open();
mycommand.Fill(dr,"sss");
}
catch(Exception ee)
{
this.TextBox1.Text=ee.Message;
Response.Write("ee="+ee.Message);
}
finally
{
myconnection.Close();
}
return;还没执行,你就return回去了!把return去掉,再看看!
try
{
}
catch
{
}
finally
{
} 就跳出去了
第2次我加上再去掉
显示的是 未将对象引用设置到对象的实例。
程序是执行完了的 郁闷了 到底是哪儿出错了 救命!!!!!!!