C#数据库类的使用方法

来源:百度知道 编辑:UC知道 时间:2024/05/18 10:07:26
C#连接数据库虽然可以使用控件绑定数据集的方法,但是这样的方法不是很灵活,我想用类实现,下面是网上照到的:(VS2005下调试成功)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.IO;

namespace ConnectionDb
{

public partial class Form1 : Form
{
public SqlConnection con;
string strCon = "server=Eagle;database=hisbook";
string ErrLogPath = "错误存放的路径";
//public SqlConnection getConnection(string strCon)
//{
// SqlConnection con = new SqlConnection(strCon);
// con.Open();
// return con;
// //SqlCommand com = new SqlCommand("select * from 药品分类",con);
// //SqlDataReader dr =com.ExecuteReader();
//

你可以去Webcast下一点微软的视频教程,有专门讲这个的
http://www.microsoft.com/china/msdn/events/webcasts/shared/Webcast/MSDNWebCast.aspx