62,177
社区成员
发帖
与我相关
我的任务
分享
public MySQLConnection Connection(string username, string password)
{
string connstr = "Data Source = babyboy;" + "Password = " + password + "; User ID = "+ username +";Location=localhost";
MySQLConnection mysqlconn = new MySQLConnection(connstr);
return mysqlconn;
}
public bool UserLogin(string username, string password)
{
CreateAndCloseConnection cacc = CreateAndCloseConnection.Instance();
this.MySqlConn = cacc.Connection(username, password);
this.MySqlConn.Open();
if (this.MySqlConn.State == ConnectionState.Open) //这个判断是对的,就是能够打开
{
return true;
}
else
{
return false;
}
}
String sqlSearch = "select * from info";
MySQLCommand cmd = new MySQLCommand(sqlSearch, mysqlconn);
MySQLDataReader my = cmd.ExecuteReaderEx(); //一运行到这句就提示错
// 误“MySQLDriverCS.MySQLException”类型的未经处理的异常出现在 MySQLDriverCS.dll 中。
//其他信息: 外部组件发生异常。
//后来 我又上网看, 改为用一下代码:
MySQLDataAdapter dt = se.SelectInfo("*", "info", null);
DataSet ds = new DataSet();
dt.Fill(ds, "info"); //一运行到这句也是提示 跟上面的错误一样。
public MySQLDataAdapter SelectInfo(string sql, MySQLConnection mysqlconn)
{
MySQLDataAdapter myReader = new MySQLDataAdapter(sql, mysqlconn);
return myReader;
}