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 =
相关文档:
1.asp.net呼叫js
Response.Write("<script language=javascript>");
&n ......
乱码真是个令人讨厌的问题~
刚才终于把MySQL与JSP交互的乱码问题解决了。
办法如下:
1.在url处加上句子 "&useUnicode=true&characterEncoding=GBK" ;
2.我用Navicat Lite可视化工具创建MySQL数据库时,可选定数据库编码,也是 GBK ;
3.页面的编码可以选GBK以外的编码方式,如UTF-8。若操作页面的编码是UTF- ......
一.字符串类
CHARSET(str) //返回字串字符集
CONCAT (string2 [,... ]) //连接字串
INSTR (string ,substring ) //返回substring首次在string中出现的位置,不存在返回0
LCASE (string2 ) //转换成小写
LEFT (string2 ,length ) //从string2中的左边起取length个字符
LENGTH (string ) //string长度
LO ......
Mysql,SqlServer,Oracle主键自动增长的设置
1、把主键定义为自动增长标识符类型
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key not null, name varchar(15));
insert into customers(name) values("name1"),("nam ......
mysql编码应注意的环节:
这几个环节编码都统一了,一般不会出现乱码。BTW:
可以用SET NAMES x临时设置mysql编码:
相当于
SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;
如:
mysql_query("SET NAMES 'gb2312'") or die("Query failed : " . mysql_er ......