请问Text字符怎样和SqlDataReader定义的量比较?我在做一个注册窗口,SqlDataReader dr = sel.ExecuteReader();这句定义的dr,怎么用它遍历的值和TextBox.Text比较?这是为了确定数据库中没有TextBox1的,求教。
protected void Button1_Click(object sender, EventArgs e)
{
String connectionstr = "server=.\SQLEXPRESS;database=mysql;integrated security=sspi";
SqlConnection myconnection = new SqlConnection(connectionstr);
try
{
string myselect = "select users from client";
SqlCommand sel = new SqlCommand(myselect);
sel.Connection = myconnection;
myconnection.Open();
SqlDataReader dr = sel.ExecuteReader();
while (dr.Read())
{
//Response.Write(dr[0]);
if ((TextBox1.Text.Equals(dr[0])) == true)
{
Response.Write("alert('该用户名已注册!')");
}
else
{
string myinsert = "insert into client(users,password) values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand ins = new SqlCommand(myinsert);
ins.Connection = myconnection;
ins.ExecuteNonQuery();
}
}
myconnection.Close();
}
catch (Exception)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=javascript>alert('失败了');</Script>");
}