微軟的visual studio沒有自帶連接Mysql的驅動
下面是我封裝好的連接數據庫的類
using System;
using System
using System
using System
using System
using System
using System
using MySql
namespace DAL
{
public class GetConnection
{
private static MySqlConnection _connection;
/// <summary>
/// 獲取數據庫連接橋
/// </summary>
private static MySqlConnection Connection
{
get
{
//string connectionString = ConfigurationManager
string connectionString = "server=localhost;user id=root; password=root; database=system; pooling=false";
//server=
//string connectionString = "Data Source=
if (_connection == null)
{
_connection = new MySqlConnection(connectionString);
_connection
}
if (_connection
{
_connection
}
if (_connection
{
_connection
_connection
}
return GetConnection
}
}
/// <summary>
/// 獲取表數據
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static MySqlDataReader GetDataRead(string sql)
{
MySqlCommand command = new MySqlCommand(sql
MySqlDataReader read = command
return read;
}
public static int NoSelect(string sql)
{
MySqlCommand command = new MySqlCommand(sql
int row = command
return row;
}
public static DataTable GetDataTable(string sql)
{
MySqlCommand command = new MySqlCommand(sql
DataTable dt = new DataTable();
MySqlDataAdapter sda = new MySqlDataAdapter(command);
sda
return dt;
}
/// <summary>
/// 執行sql語句
/// </summary>
/// <param name="sql">SQL語句</param>
/// <returns></returns>
public static string GetScalar(string sql)
{
MySqlCommand command = new MySqlCommand(sql
return command
}
}
}
比 如說你想執行刪除的
From:http://tw.wingwit.com/Article/program/net/201311/14014.html