c# 访问数据库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        MySqlConnection con = new MySqlConnection("Host = localhost;Database = www;" + "Username = root; Password = 123456");

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            MySqlCommand com1 = new MySqlCommand();
            com1.Connection = con;
            com1.CommandText = "insert into user values(014,'小花','高二','sser')," + "(84,'小花01','高三','和谐')";
            int i = com1.ExecuteNonQuery();
            con.Close();
        }
    }
}

posted @ 2011-12-11 20:29  softimagewht  阅读(159)  评论(0编辑  收藏  举报