c#的类
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;
namespace test2
{
class DataBase
{
public static String sqlconn = @"Data Source=LXL;Initial Catalog=Stu;User ID=sa;password=sa";
private SqlConnection conn;
public void open()
{
if (this.conn == null)
{
this.conn = new SqlConnection(sqlconn);
}
this.conn.Open();
}
public void close()
{
if (this.conn != null)
{
this.conn.Close();
}
}
public DataView runSelectSQL(String sql)
{
this.open();
SqlDataAdapter sda = new SqlDataAdapter(sql, this.conn);
DataSet ds = new DataSet();
sda.Fill(ds);
this.close();
return ds.Tables.DefaultView;
}
public DataSet getResultToDataSet(String sql)
{
this.open();
SqlDataAdapter sda = new SqlDataAdapter(sql, this.conn);
DataSet ds = new DataSet();
sda.Fill(ds);
this.close();
return ds;
}
//new DataBase().FillCb("sexTable","sex","id",cmbSex);
public void FillCb(string sTableName,
string sDisplayMember,
string sValueMember,
ComboBox cb)
{
DataView dv = new DataView();
string sSql = "select distinct "
+ sDisplayMember + ","
+ sValueMember +
"from " + sTableName;
dv = this.runSelectSQL(sSql);
cb.DataSource = dv;
cb.DisplayMember = sDisplayMember;
cb.ValueMember = sValueMember;
}
public intrunUpdateSQL(String sql)
{
this.open();
SqlCommand cmd = new SqlCommand(sql, conn);
int n = cmd.ExecuteNonQuery();
this.close();
return n;
}
public int getRecordCount(string sSQLString)
{
int nCount;
this.open();
SqlCommand SqlComm;
try
{
SqlComm = new SqlCommand(sSQLString, this.conn);
nCount = Convert.ToInt32(SqlComm.ExecuteScalar());
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
nCount = -1;
}
this.close();
return nCount;
}
}
} ????这是什么啊??对于我来说!1不懂!! 嘿嘿
不错哦
要不要把记事本的程序也弄上来呀 ..哈哈~老师的也发上来。
那么有空帮我做个系统呀..
页:
[1]