Baolu-net
o(∩_∩)o ~~ 菜人 ~~ 啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
随笔 - 8, 文章 - 3, 评论 - 12, 引用 - 0
数据加载中……
【原创】当C#遇到MySql (用C#访问MySql数据库)
基本上这个就是我的第一个C#程序了吧 o(∩_∩)o... 还挺顺利的
首先解决驱动问题
1:下载MySQL.VisualStudio-1.1.2
2:下载Mysql-connector-net-5.0.3
3:下载MySql数据库5.0x
using
System;
using
System.Collections.Generic;
using
System.Text;
using
MySql.Data.MySqlClient;
namespace
CSDB
{
class
MySQLResults
{
public
MySQLResults(
string
sql)
{
MySqlConnection conn
=
null
;
MySqlCommand command
=
null
;
MySqlDataReader reader
=
null
;
try
{
conn
=
new
MySqlConnection(
"
Server=localhost;User Id=baolu;Password=baolu;Persist Security Info=True;Database=baolu_db
"
);
command
=
conn.CreateCommand();
command.CommandText
=
sql;
conn.Open();
reader
=
command.ExecuteReader();
while
(reader.Read())
{
Console.WriteLine(reader[
0
]);
Console.WriteLine(reader[
1
]);
Console.WriteLine(reader[
2
]);
}
}
catch
(MySqlException se)
{
Console.WriteLine(
"
Database operation errors :
"
+
se.StackTrace);
conn.Close();
command
=
null
;
reader.Close();
}
}
}
}
using
System;
using
System.Collections.Generic;
using
System.Text;
using
MySql.Data.MySqlClient;
namespace
CSDB
{
class
Program
{
static
void
Main(
string
[] args)
{
new
MySQLResults(
"
select * from user
"
);
}
}
}
参考书籍:【Sybex - Mastering C# Database Programming】
posted on 2007-05-13 03:37
宝露o(∩_∩)o
阅读(469)
评论(2)
编辑
收藏
网摘
评论
#1楼
回复
引用
查看
好文,拿来收藏哈!
2007-05-16 12:32 |
小罗
#2楼
回复
引用
加点注释吧,初学者很多看不懂
2007-07-20 10:22 |
gb [未注册用户]
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
人才
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2007-05-13 04:24 编辑过
Google站内搜索
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
相关文章:
相关链接:
最新IT新闻:
Silverlight 2 SDK中文版发布
[译稿]微软将 jQuery IntelliSense整合到Visual Studio
微软:不裁员也不削减研发开支
2008年11月22日科技博客精选
诺基亚将支持Lotus Notes 和黑莓争夺市场
Powered by:
博客园
Copyright © 宝露o(∩_∩)o
导航
博客园
首页
新随笔
联系
订阅
管理
<
2007年5月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(1)
给我留言
查看留言
随笔分类
A&Q(1)
(rss)
随笔档案
2007年5月 (8)
文章分类
.Net Programming
(rss)
.Net Resources
(rss)
C# Database Programming
(rss)
C# Programming
(rss)
Reference Articles(3)
(rss)
收藏夹
资源
(rss)
最新评论
阅读排行榜
1. 遇到问题了 .net项目发布到iis6,没有权限访问!?(1882)
2. 【原创】当C#遇到MySql (用C#访问MySql数据库)(469)
3. 【分享】初学者必须资源 Visual Studio 2005 Express Editons 镜像下载地址(301)
4. 【转贴】详细解读Express版与付费版本的差别(283)
5. 【原创】在窗体项目的类中获得当前窗体的对象(272)
评论排行榜
1. 遇到问题了 .net项目发布到iis6,没有权限访问!?(7)
2. 【原创】傻大傻大的发现了About对话框(2)
3. 【原创】当C#遇到MySql (用C#访问MySql数据库)(2)
4. 【转贴】详细解读Express版与付费版本的差别(1)
5. 【原创】在窗体项目的类中获得当前窗体的对象(续)(0)