System.Data.SqlClient.SqlException: '1' 附近有语法错误。
源错误:27:SqlDataReaderdr=cmd.ExecuteReader();stringstrconn="datasource=.;database=hh;in...
源错误: 27: SqlDataReader dr = cmd.ExecuteReader();
string strconn = "data source=.;database=hh;integrated security=true";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sqlconn = "select count(*) from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima'" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(sqlconn, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Response.Write("<script>alert('用户名密码正确!');</script>");
Server.Transfer("dl4.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!');</script>");
}
dr.Close();
conn.Close(); 展开
string strconn = "data source=.;database=hh;integrated security=true";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sqlconn = "select count(*) from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima'" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(sqlconn, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Response.Write("<script>alert('用户名密码正确!');</script>");
Server.Transfer("dl4.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!');</script>");
}
dr.Close();
conn.Close(); 展开
展开全部
你改成这样试试:
string strconn = "data source=.;database=hh;integrated security=true";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sqlconn = "select count(*) as count from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima'" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(sqlconn, conn);
SqlDataReader dr = cmd.ExecuteReader();
int count=0;
if (dr.Read())
{
count=Convert.ToInt32(dr["count"]);
}
if( count>0){
Response.Write("<script>alert('用户名密码正确!');</script>");
Server.Transfer("dl4.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!');</script>");
}
dr.Close();
conn.Close();
string strconn = "data source=.;database=hh;integrated security=true";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sqlconn = "select count(*) as count from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima'" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(sqlconn, conn);
SqlDataReader dr = cmd.ExecuteReader();
int count=0;
if (dr.Read())
{
count=Convert.ToInt32(dr["count"]);
}
if( count>0){
Response.Write("<script>alert('用户名密码正确!');</script>");
Server.Transfer("dl4.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!');</script>");
}
dr.Close();
conn.Close();
追问
还是不行,也是这个句子有错误:源错误: 27: SqlDataReader dr = cmd.ExecuteReader();
怎么总是这个错误的?刚学不久,还是菜鸟阶段的
追答
//定义数据库连接字符串
string strconn = "data source=.;database=hh;integrated security=true";
//定义sql语句
string sqlconn = string.formart("select count(*) as count from dl_yonghu where dl_user='{0}' and dl_mima='{1}'" ,TextBox1.Text ,TextBox2.Text );
//创建数据库连接
SqlConnection conn = new SqlConnection(strconn);
//打开数据库连接:
conn.Open();
//创建命令
SqlCommand cmd = new SqlCommand(sqlconn, conn);
//调用查询方法
SqlDataReader dr = cmd.ExecuteReader();
int count=0;
if (dr.Read())
{
count=Convert.ToInt32(dr["count"]);
}
if( count>0){
Response.Write("alert('用户名密码正确!');");
Server.Transfer("dl4.aspx");
}
else
{
Response.Write("alert('用户名或密码不正确!');");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string sqlconn = "select count(*) from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima'" + TextBox2.Text + "'";
应为:
string sqlconn = "select count(*) from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima='" + TextBox2.Text + "'";
少了一个等于号
应为:
string sqlconn = "select count(*) from dl_yonghu where dl_user='" + TextBox1.Text + "'and dl_mima='" + TextBox2.Text + "'";
少了一个等于号
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询