C# 连接MYSQL 本地数据库路径问题

WoooP 发布于 2014/06/14 15:44
阅读 856
收藏 0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        string MyconnectionString = "Server=127.0.0.1;Databass=test;Uid=root;Pwd=";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int MobileNo;
            string Mobile = txtMobile.Text;
            int.TryParse(Mobile, out MobileNo);
            MySqlConnection connection = new MySqlConnection(MyconnectionString); MySqlCommand cmd;
            connection.Open();
            try
            {
                cmd = connection.CreateCommand();
                cmd.CommandText = "INSERT INTO PHONEBOOK(ID,NAME,MOBILENO)VALUES(@ID,@NAME,@MOBILENO)";
                cmd.Parameters.AddWithValue("@ID", int.Parse(txtid.Text));
                cmd.Parameters.AddWithValue("@NAME", int.Parse(txtName.Text));
                cmd.Parameters.AddWithValue("@MobileNo", MobileNo);
                cmd.ExecuteNonQuery();
            }
            catch(Exception)
            {
                throw;
            }
            finally
            {
                if(connection.State == ConnectionState.Open){
                    connection.Close();
                    LoadData();
                }
            }
        }
        private void LoadData()
        {
            MySqlConnection conection = new MySqlConnection(MyconnectionString);
            conection.Open();
            try
            {

            }
            catch(Exception){
                throw;
            }
            finally
            {
                if(conection.State == ConnectionState.Open){
                    conection.Close();
                }
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }
    }
}
MySqlConnection connection = new MySqlConnection(MyconnectionString);

这里通不过,我的MYSQL本地安装路径为:

D:\web\APMServ5.2.6\MySQL5.1

数据库



加载中
返回顶部
顶部