SqlConnection conn = 
new SqlConnection(ConfigurationSettings.AppSettings["sanjia"]);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
string sql = "";
sql = "SELECT COUNT(*) AS users_found2 FROM oauser WHERE (username = '" + TextBox1.Text + "') or (loginname = '" +TextBox2.Text+ "')";
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
cmd.Connection = conn;
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
if (reader.GetValue(0).ToString() != "0")
{
Label1.Text = "真实姓名或登录名以存在!";
}
else
{
SqlConnection MyConnection;
SqlCommand MyCommand;
String ConnStr;
MyConnection =new SqlConnection(ConfigurationSettings.AppSettings["sanjia"]);
MyConnection.Open();
if ((SID.Text.Trim()=="")||(TextBox1.Text.Trim()=="")||(TextBox2.Text.Trim()=="")||(TextBox3.Text.Trim()=="")||(TextBox4.Text.Trim()=="")) 
{
Label1.Text="前五项不能为空!";
}
else if (TextBox1.Text.Trim().Length>=8)
{
Label1.Text="你的用户名太长了!";
}
else if (TextBox2.Text.Trim().Length>=10)
{
Label1.Text="你的登录太长了!";
}
else if (TextBox3.Text.Trim().Length>=13)
{
Label1.Text="你的密码太长了!";
}
else if (TextBox3.Text.Trim().Length<4)
{
Label1.Text="你的密码太短了!";
}
else if (TextBox4.Text.Trim()!=TextBox4.Text.Trim())
{
Label1.Text="你的密码不一致!";
}
else
{
ConnStr="insert into oauser(sid,username,loginname,password,email,call,tel,address,dept,userright,sfkq) VALUES('"+SID.Text+"','"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox5.Text+"','"+TextBox6.Text+"','"+TextBox7.Text+"','"+TextBox8.Text+"','"+DropDownList1.SelectedItem.Text+"','"+DropDownList2.SelectedItem.Text+"','"+RadioButtonList1.SelectedItem.Value+"')";
MyCommand=new SqlCommand(ConnStr,MyConnection);
MyCommand.ExecuteNonQuery();
Label1.Text="增加成功!";
}
}
}
}