急求 VS winform 窗体程序 操作mysql数据库方法 有代码 更好
usingSystem.Windows.Forms;usingMySql.Data.MySqlClient;namespaceQQlogin{publicpartialc...
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace QQlogin
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private string str = "server=localhost;uid=root;pwd=;database=test;Charset=utf8";
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(str);
con.Open();
string sql = string.Format("select count(*) from csvinfo where csvid='{0}' and csvname='{1}'", textBox1.Text, textBox2.Text);
MySqlCommand cmd = new MySqlCommand(sql, con);
int num = cmd.ExecuteNonQuery();
con.Close();
if (num == 1)
{
MainForm stu = new MainForm();
stu.Show();
this.Visible = false;
}
else
{
MessageBox.Show("输入的信息有误!");
}
}
}
}
..///用VS开发总是在con.Open();的时候哦说:'System.Transactions.Diagnostics.DiagnosticTrace'。。。。。。? 展开
using MySql.Data.MySqlClient;
namespace QQlogin
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private string str = "server=localhost;uid=root;pwd=;database=test;Charset=utf8";
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(str);
con.Open();
string sql = string.Format("select count(*) from csvinfo where csvid='{0}' and csvname='{1}'", textBox1.Text, textBox2.Text);
MySqlCommand cmd = new MySqlCommand(sql, con);
int num = cmd.ExecuteNonQuery();
con.Close();
if (num == 1)
{
MainForm stu = new MainForm();
stu.Show();
this.Visible = false;
}
else
{
MessageBox.Show("输入的信息有误!");
}
}
}
}
..///用VS开发总是在con.Open();的时候哦说:'System.Transactions.Diagnostics.DiagnosticTrace'。。。。。。? 展开
1个回答
展开全部
要操作mysql数据库,首先下载MySql.Data.dll组件
然后引用这个组件,使用 MySqlHelper 类来执行sql
http://zhidao.baidu.com/question/235878960.html
然后引用这个组件,使用 MySqlHelper 类来执行sql
http://zhidao.baidu.com/question/235878960.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询