推荐文章

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增

C#连接mySQL数据库

日期:2018-07-05 点击:1404 来源:PB2.CN

C#连接MySql所需的库文件MySQLDriverCS,由两个文件组成libmySQL.dll,MySQLDriverCS.DLL。
将libmySQL.dll拷贝到c:\windows\system32目录下,然后将MySQLDriverCS.DLL引入到C#或ASP.NET工程。

(引入操作:项目右键->添加引用->浏览)

在代码中

using MySQLDriverCS;

MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("数据库IP地址","数据库名" "用户名", "密码").AsString); 
MySQLCommand cmd = new MySQLCommand("SQL语句", conn); 
conn.Open(); 
cmd.ExecuteNonQuery(); 
Conn.Close(); 

具体例子
using MySQLDriverCS;
// 建立数据库连接
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString("localhost","mysql","root","",3306).AsString);
DBConn.Open();
// 执行查询语句
MySQLCommand DBComm;
DBComm = new MySQLCommand("select Host,User from user",DBConn);
// 读取数据
MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
// 显示数据
try
{
while (DBReader.Read())
{
Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0),DBReader.GetString(1));
}
}
finally
{
DBReader.Close();
DBConn.Close();
}
//关闭数据库连接
DBConn.Close();



这篇文档对您是否有帮助?

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增