怎么在textbox7插入数据库前判断已存在并弹出提示框,就像下面已经写好的”用户名已存在那样“
namespace InternetShopping.AdminManage
{
public partial class UserRegister : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select count(*) from Custom";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int numcount = Convert.ToInt32(command.ExecuteScalar());
numcount++;
TextBox7.Text=numcount.ToString ();
}
protected void Button1_Click1(object sender, EventArgs e)
{
string UserName = this.TextBox1.Text;
TextBox1.Text = "";
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select *from Custom where customName='" + UserName + "'";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int num1 = Convert.ToInt32(command.ExecuteScalar());
if (num1 > 0 )
{
Response.Write("<script>alert('用户名已存在');</script>");
}
else
{
SqlDataSource1.Insert();
Response.Redirect("BuyComputerBooks.aspx");
}
connect.Close();}}
}
namespace InternetShopping.AdminManage
{
public partial class UserRegister : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select count(*) from Custom";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int numcount = Convert.ToInt32(command.ExecuteScalar());
numcount++;
TextBox7.Text=numcount.ToString ();
}
protected void Button1_Click1(object sender, EventArgs e)
{
string UserName = this.TextBox1.Text;
TextBox1.Text = "";
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select *from Custom where customName='" + UserName + "'";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int num1 = Convert.ToInt32(command.ExecuteScalar());
if (num1 > 0 )
{
Response.Write("<script>alert('用户名已存在');</script>");
}
else
{
SqlDataSource1.Insert();
Response.Redirect("BuyComputerBooks.aspx");
}
connect.Close();}}
}
解决方案 »
- 抓取网页数据,求取出正则
- SqlDataSource怎么用UpdateCommand更新
- 想实现一个点击显示图片,在图片上框取得到所框取的四个角的座标
- 求一正则表达式,字符串不允许包含"\/@^&?<>[]*"中的任一字符,谢谢
- 初学者请教,请问如何在net中加入treeview组件呢?
- 字符串
- 我想将DATAGRID的表头实现如内所示,请问该如何做。。。。
- 谁有编译过的Infragistics.NetAdvantage.2004.Vol.2,源代码编译我没有通过
- 怎么把一个http上的文件都城二进制流?
- 关于window.showModalDialog
- 第一天学NET 问个简单问题 简单控制台 IF else
- 问一下,关于MVC 排序的问题
{
public partial class UserRegister : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string txtName=TextBox7.Text;
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select txtName from Custom where txtName="txtName";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int numcount = Convert.ToInt32(command.ExecuteScalar());
if (numcount.length>0 )
{
Response.Write("<script>alert('用户名已存在');</script>");
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
string UserName = this.TextBox1.Text;
TextBox1.Text = "";
string num = ("Server=(local);Integrated Security=SSPI;database=bookshopping");
SqlConnection connect = new SqlConnection(num);
string sql = "select *from Custom where customName='" + UserName + "'";
SqlCommand command = new SqlCommand(sql, connect);
connect.Open();
int num1 = Convert.ToInt32(command.ExecuteScalar());
if (num1 > 0 )
{
Response.Write("<script>(function(){alert('用户名已存在');})()</script>");
}
else
{
SqlDataSource1.Insert();
Response.Redirect("BuyComputerBooks.aspx");
}
connect.Close();}