RT,代码本人直接贴了……
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication1
{
public class ClassConnect
{
MySqlConnectionStringBuilder cs = new MySqlConnectionStringBuilder();
cs.Server = “127.0.0.1”;
cs.Port = 3306;
cs.Database = “user_system”;
cs.UserID = “root”;
cs.Password = “”;
MySqlConnection connect = new MySqlConnection(cs.ConnectionString);
connect.Open();
}
}
马上给本人弹出来上下文中不存在cs还有connect.open()函数=。=你在逗本人?本人的声明明明就顶在上头你告诉本人不行?TAT
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication1
{
public class ClassConnect
{
MySqlConnectionStringBuilder cs = new MySqlConnectionStringBuilder();
cs.Server = “127.0.0.1”;
cs.Port = 3306;
cs.Database = “user_system”;
cs.UserID = “root”;
cs.Password = “”;
MySqlConnection connect = new MySqlConnection(cs.ConnectionString);
connect.Open();
}
}
马上给本人弹出来上下文中不存在cs还有connect.open()函数=。=你在逗本人?本人的声明明明就顶在上头你告诉本人不行?TAT
解决方案
50
额。楼猪你这是把函数内容写在了类定义里面。建议先弄清楚类和函数的概念,反省下是基础不熟还是喝酒断片吧。
public class ClassConnect { private void dosomething(){ MySqlConnectionStringBuilder cs = new MySqlConnectionStringBuilder(); cs.Server = "127.0.0.1"; cs.Port = 3306; cs.Database = "user_system"; cs.UserID = "root"; cs.Password = ""; MySqlConnection connect = new MySqlConnection(cs.ConnectionString); connect.Open(); } }