private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection myConnection=new SqlConnection("server=(local);uid=sa;pwd=;database=li");
SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"',mima='"+TextBox2.Text+"'",myConnection);//这句查询语句好象从数据库中找不到文本框输入的内容.....怎么改
try
{
myConnection.Open();
mySqlCommand.ExecuteReader();
Response.Redirect("WebForm3.aspx");
}
catch(Exception)
{
Label3.Text="没有此用户名".ToString();
}
finally
{
myConnection.Close();
}
}
解决方案 »
- gridView 不能显示数据源!
- 为什么在网站上提交信息之后会提示invalid word,然后页面就死掉呢?
- WORD 文件打开的问题
- 前辈介绍一本关于asp.net的书
- (求助)vs.net:“活动架构不支持ListItem”(肯请指教)
- petshop 在.net 2005下能否安装??
- 高手请进
- 在css那个版中没有问出结果,还是到这来吧?
- gridview中添加,运行时可输入文字的textbox,后台判断textbox change时做一些操作
- 有实现asp.net 链接数据库实现字体跑马灯效果的代码吗?
- 用Membership.CreateUser(name,password......)新建用户时总是报错,我想用户的信息肯定是保存在SQLSERVER里面的,那么可能是那个数据库
- 一个难点:如何在web客户端为ListBox增加(或删除)一个option 或下下拉列表框增加(或删除)也一样。难呀?
select name,mima from denglu where name='"+TextBox1.Text+"',mima='"+TextBox2.Text+"'"
可以像这样写吗?多条件查询要用AND联接还不是用“,”
select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'"
而且你的密码怎么加密算法都没有一个呢?
myConnection.Open();
mySqlCommand.ExecuteReader();
Response.Redirect("WebForm3.aspx");
找不到数据也不会产生异常的。
SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
try
{
myConnection.Open();
mySqlCommand.ExecuteReader();
Response.Redirect("WebForm3.aspx");
}
catch(Exception)
{
Label3.Text="没有此用户名".ToString();
}
finally
{
myConnection.Close();
}
我在WebForm1.aspx中拖了两个TextBox 一个提交botton 在文本框中输入用户名.密码,,然后在数据库中查询,查到转到WebForm3.aspx页面,,查询好像有问题啊,我数据库中已经有信息了,可是输入查询总是Label3显示"没有此用户名".
SqlConnection myConnection=new SqlConnection("server=local);uid=sa;pwd=****(没有写啊);database=li");
myConnection.Open();
SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
try
{
mySqlCommand.ExecuteReader();
Response.Redirect("WebForm3.aspx");
}
catch(Exception)
{
Label3.Text="没有此用户名".ToString();
}
finally
{
myConnection.Close();
}
SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
SqlDataReader dr;
try
{
myConnection.Open();
dr = mySqlCommand.ExecuteReader();
if(dr.read())
{
Response.Redirect("WebForm3.aspx");
}
else
{
Label3.Text="没有此用户名".ToString();
}
}
catch(Exception E)
{
Response.Write(E.Message);
}
finally
{
myConnection.Close();
}