注册 登录
编程论坛 C# 论坛

c#链接mysql的问题

l2480035288 发布于 2014-12-13 20:30, 442 次点击
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using MySQLDriverCS;
namespace 数据库
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {

            string con, sql;
            con = "server=localhost;Database=dianming;User id=root;Password=111111";
            sql = "select * from student";
            SqlConnection mycon = new SqlConnection(con);
            SqlDataAdapter da = new SqlDataAdapter(sql, mycon);
            DataSet das = new DataSet();
            da.Fill(das, "student");
            dataGridView1.DataSource = das.Tables["student"];

        }

    }
}

按照网上教程打 可是程序运行没反应,也链接不上数据库,哪里错了呢    程序主要是测试数据库是否连接上来  

界面图
只有本站会员才能查看附件,请 登录
2 回复
#2
黄博森2014-12-14 10:58
你试试在数据库的表中加入id将它设置为主键,我上次的问题跟你的一样。
#3
xydddaxia2014-12-15 14:22
连接mysql怎么能用Sqlserver的类
SqlConnection
SqlDataAdapter
应用
MySQLConnection
MySQLCommand
MySQLDataAdapter
等等
1