private void Button1_Click(object sender, System.EventArgs e) { if(Page.IsValid) { if(UserValid()) { SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sqlconnectionstring"]); conn.Open();
string sql = "Insert into Users(UserName,Password,Email) values('" + this.UserName.Text + "','" + this.Password.Text + "','" + this.email.Text + "')"; SqlCommand cmd = new SqlCommand(sql,conn); try { cmd.ExecuteNonQuery(); } catch { } finally { cmd.Dispose(); conn.Close(); } this.Panel1.Visible = false; this.Panel2.Visible = true; } else { this.Label1.Visible = true; } } } private bool UserValid() { SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sqlconnectionstring"]); conn.Open(); string sql = "select * from Users where UserName = '" + this.UserName.Text + "'"; SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader reader = cmd.ExecuteReader(); if(reader.Read()) { return false; } else { return true; } } 简单的注册信息,麻烦看下,我只弄了几个TBO控件而已~~~~~~~ 怎么提示注册成功,可数据库里面没有呢?????cmd.ExecuteNonQuery();我这个不是已经提交了么???为什么呢??? 连接数据库的语句是在WEB.CONFIG <appSettings> <add key="sqlConnectionString" value="Data Source=(local);uid=sa;pwd=sa;database=BBS" /> </appSettings>