找回密码
 入驻
搜索
查看: 300|回复: 3

c#的类

[复制链接]
发表于 2009-4-30 10:17:56 | 显示全部楼层 |阅读模式
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[0].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 int  runUpdateSQL(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;
        }


    }
}
发表于 2009-4-30 10:20:52 | 显示全部楼层
????这是什么啊??对于我来说!1不懂!!
回复

使用道具 举报

发表于 2009-4-30 10:24:19 | 显示全部楼层
嘿嘿
不错哦
要不要把记事本的程序也弄上来呀
回复

使用道具 举报

发表于 2009-4-30 11:14:58 | 显示全部楼层
..哈哈~老师的也发上来。
那么有空帮我做个系统呀..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 入驻

本版积分规则

QQ|Archiver|手机版|小黑屋|思明论坛

GMT+8, 2024-5-13 12:51 , Processed in 0.036072 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表