代码未处理 sqlexception

来源:百度知道 编辑:UC知道 时间:2024/05/14 09:20:10
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void login_Click(object sender, EventArgs e)
{
string name = nm.Text.ToString();
string pw = pwd.Text.ToString();
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["mysqlconnection"]);
SqlConnection myconn = new SqlConnection(settings);
myconn.Open();
string mysql="select * from admin_test where name

当然是 myconn.Open(); 这句话出了问题,也就是你连接的服务器无法连接或你指定了错误的连接字符串。
你调试一下,看看 SqlConnection myconn = new SqlConnection(settings);
这句话里面的 settings 是否是正常的连接字符串,以及它指定的服务器是否能访问。

select * from admin_test where name="+"'"+name+"'"+"and pwd="+"'"+pw+"'";

感觉你的sql语句是错的哦~~~~
select * from admin_test where name='name'and pwd='pw';
是不是少了个空格呀?在and前面.