C#数据库操作实例:
就是简单,做个小笔记,话说用using就不用关闭资源了。
using System.Windows.Forms; using MySql.Data.MySqlClient; namespace login { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { string mysqlcon = "server=localhost;database=db;user=root;password=usbw;port=3307;"; MySqlConnection conn = new MySqlConnection(mysqlcon); conn.Open(); string find = string.Format("select * from text where adminname= '{0}'and adminpassword='{1}' ",this.textBox1.Text.Trim(),this.textBox2.Text.Trim()); MySqlCommand comm = new MySqlCommand(find, conn); object num; num=comm.ExecuteScalar(); if (num !=null) { MessageBox.Show("登陆成功!"); } conn.Close(); conn.dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }