代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MODEL;
using MySql.Data.MySqlClient;
using MySQLDriverCS;
namespace DAL
{
public class Dal
{
public static int getUserInformation(UserInformation user)
{
MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection("Database='salesmis';Data Source='localhost';User Id='root';Password='123456';charset='utf8'");
con.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "select count(*) from userlogin where username=@name and password=@pwd";
cmd.Parameters.Add(new MySQLParameter("@name", user.getUserName()));
cmd.Parameters.Add(new MySQLParameter("@pwd", user.getPassword()));
String name = user.getUserName();
string pwd = user.getPassword();
int count = Convert.ToInt32(cmd.ExecuteScalar());
return count;
}
}
}注:本人采用三层架构模式来连接Mysql数据库,这是Dal层,这要是获取数据库salesmis中user的信息并提交给login函数处理。
编译后,系统提示:“一个未处理的异常类型的MySql.Data.MySqlClient。 发生在MySql.Data.dll MySqlException”
附加信息:只有MySqlParameter对象可以存储
抛出”
错误指向这几行代码:
cmd.Parameters.Add(new MySQLParameter("@name", user.getUserName()));
cmd.Parameters.Add(new MySQLParameter("@pwd", user.getPassword()))
本人在此跪求各位英雄好汉帮忙解答一下,万分感谢
不负相思意