C#连接MySql数据库方法
宇兰
1、用MySQLDriverCS连接MySQL数据库
先下载和安装MySQLDriverCS,地址:http://sourceforge.net/projects/mysqldrivercs/在安装文件夹下面找到MySQLDriver.dll,然后将MySQLDriver.dll添加引用到项目中注:我下载的是版本是 MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.Odbc;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using MySQLDriverCS; namespace mysql{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { MySQLConnection conn = null; conn = new MySQLConnection(new MySQLConnectionString("localhost", "inv", "root", "831025").AsString); conn.Open(); MySQLCommand commn = new MySQLCommand("set names gb2312", conn); commn.ExecuteNonQuery(); string sql = "select * from exchange "; MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn); DataSet ds = new DataSet(); mda.Fill(ds, "table1"); &n
相关文档:
基础部分
一、MySQL 获得当前日期时间 函数
1.1 获得当前日期+时间(date + time)函数:now()
mysql> select now();
+---------------------+
| now() |
+----------------- ......
http://www.blogjava.net/Alpha/archive/2007/07/23/131912.html
//主键549830479
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列549830479
alter table t2 add d timestamp;
alter table infos add ex tinyint n ......
2007-11-16 15:37
今天看着手册试了下,发现原来大数据导入导出是那么的轻松(不是很大,200多M的文本而以)
注意:如果发现MYSQL unknown command '\'这样的提示,则设置一下服务器的字符集,如:
mysql -uroot -ppasspass --default-character-set=utf8 databaseName <d:bakcup.sql
这样就不会报错了,^_^
导出 ......
如若转载本文,请注明原始出处:http://hi.baidu.com/hexiong/blog/item/e860e5dd9b0d3ae376c6381a.html
(hexiong@baidu or iihero@CSDN)
偶尔碰到有人问使用mysql命令行,老让人输入--default-character-set=gbk之类无聊的选项,让人烦。让人多输入了几个字符,确实有点不对劲。
加上有时候自己有时候DIY,很少在window ......