[c#]代码库
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
namespace MySql_DB
{
public class DBHelper
{
private static string constr = "server=localhost;User Id=root;password=root;Database=dbtest";
public static int Execute(string sql)
{
try
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand com = new MySqlCommand(sql, con);
int num = com.ExecuteNonQuery();
con.Close();
return num;
}
catch (Exception ex)
{
return 0;
}
}
public static DataSet Select(string sql)
{
try
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlDataAdapter mda = new MySqlDataAdapter(sql, con);
DataSet ds = new DataSet();
mda.Fill(ds, "table1");
con.Close();
return ds;
}
catch (Exception ex)
{
return null;
}
}
}
}
by: 发表于:2018-01-08 10:19:23 顶(0) | 踩(0) 回复
??
回复评论