无法将类型“object”隐式转换为“bool”。存在一个显式转换(是否缺少强制转换?)
protectedvoidPage_Load(objectsender,EventArgse){}publicobjectCheckInput(){if(TextBox1...
protected void Page_Load(object sender, EventArgs e)
{
}
public object CheckInput()
{
if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "")
{
Label7.Text = "你输入信息有误!";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
return false;
}
else
{
if (TextBox2.Text != TextBox3.Text)
{
Label7.Text = "两次输入密码不同!";
TextBox2.Text = "";
TextBox3.Text = "";
return false;
}
}
return true;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckInput())
{
SqlConnection conn = new SqlConnection("Data Source=.;InitializeCulture Catalog=nie;Integrated Security=true");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select[姓名]from 学生信息表";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.GetString(0) == TextBox1.Text)
{
Label7.Text = "你注册的用户已存在,请重新注册一个!";
conn.Close();
TextBox1.Text = "";
return;
}
}
conn.Close();
string Sqlstr;
Sqlstr = "Insert into 学生信息表([姓名],[密码],[性别])values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox4.Text + "')";
cmd.CommandText = Sqlstr;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Label7.Text = "恭喜你注册成功!";
}
}
错误提示:无法将类型“object”隐式转换为“bool”。存在一个显式转换(是否缺少强制转换?) 怎么解决?? 展开
{
}
public object CheckInput()
{
if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "")
{
Label7.Text = "你输入信息有误!";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
return false;
}
else
{
if (TextBox2.Text != TextBox3.Text)
{
Label7.Text = "两次输入密码不同!";
TextBox2.Text = "";
TextBox3.Text = "";
return false;
}
}
return true;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckInput())
{
SqlConnection conn = new SqlConnection("Data Source=.;InitializeCulture Catalog=nie;Integrated Security=true");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select[姓名]from 学生信息表";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.GetString(0) == TextBox1.Text)
{
Label7.Text = "你注册的用户已存在,请重新注册一个!";
conn.Close();
TextBox1.Text = "";
return;
}
}
conn.Close();
string Sqlstr;
Sqlstr = "Insert into 学生信息表([姓名],[密码],[性别])values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox4.Text + "')";
cmd.CommandText = Sqlstr;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Label7.Text = "恭喜你注册成功!";
}
}
错误提示:无法将类型“object”隐式转换为“bool”。存在一个显式转换(是否缺少强制转换?) 怎么解决?? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询