| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1127 人关注过本帖
标题:求C#连接数据库完整代码
只看楼主 加入收藏
单行道1129
Rank: 3Rank: 3
来 自:山东潍坊
等 级:论坛游侠
帖 子:38
专家分:118
注 册:2011-10-26
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:6 
求C#连接数据库完整代码
求C#连接数据库完整代码
搜索更多相关主题的帖子: 连接数据库 
2011-10-26 20:22
zx10283
Rank: 2
等 级:论坛游民
帖 子:25
专家分:82
注 册:2011-10-20
收藏
得分:5 
                    string sqlconn = "Data Source=.;Initial Catalog=表名;Integrated Security=True";
                    
                    SqlConnection conn = new SqlConnection(sqlconn);
 
2011-10-26 20:46
yangwenwei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:28
注 册:2011-10-24
收藏
得分:0 
http://blog.,仅供参考!
2011-10-26 20:47
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:5 
程序代码:
private int SetHasEst()
        {
            string conString;

            SqlConnection sqlcon = new SqlConnection(@"Server = PC--20110803JXD\SQLEXPRESS;Database = Mltmd;User ID=sa;Password='wfl137632'");

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = sqlcon;

            int i = 1;  //1连接数据库成功,0失败

            try
            {
                sqlcon.Open();
                this.con.Open();

                conString = "SELECT * FROM Picture WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
                 = conString;
                this.picHasEst = this.getExsRows(cmd);

                conString = "SELECT * FROM Document WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
                 = conString;
                this.docHasEst = this.getExsRows(cmd);

                conString = "SELECT * FROM Record WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
                 = conString;
                this.audHasEst = this.getExsRows(cmd);

                conString = "SELECT * FROM Video WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
                 = conString;
                this.vidHasEst = this.getExsRows(cmd);

                conString = "SELECT * FROM Chart WHERE ghtpcd=" + "'" + this.tbZhtCd.Text.Trim() + "'";
                 = conString;
                this.chtHasEst = this.getExsRows(cmd);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

                i = 0;
            }
            finally
            {
                sqlcon.Close();
            }

            return i;
        }

   唯实惟新 至诚致志
2011-10-26 22:52
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
程序代码:
private void loadProvince()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = this.con;  //private SqlConnection con=new SqlConnection(@"Server = PC--20110803JXD\SQLEXPRESS;Database = Dsdv;User ID=sa;Password='wfl137632'");
             = "SELECT dsdvsn,dsdvcd FROM dsdv WHERE dsdvcd LIKE '__0000000000000'";

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                this.cbProvince.Items.Add(dr[0]);
                this.pvcdlist.Add(dr[1]);
            }

            dr.Close();
        }

   唯实惟新 至诚致志
2011-10-26 22:54
a12135a
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2011-3-26
收藏
得分:0 
系统身份登录:
Data Source=.;Initial Catalog=表名;Integrated Security=True



账户密码登录:
server=.;uid=登录名;pwd=密码;database=数据库名称
2011-10-27 16:27
clhc
Rank: 6Rank: 6
等 级:侠之大者
帖 子:69
专家分:441
注 册:2011-10-11
收藏
得分:0 
sql 无密 string host, string db, bool Security
Data Source=;Initial Catalog=?;Integrated Security=True
sql 有密 string host,string db,string usr, string pwd
Data Source=;Initial Catalog=?;UID=?;PassWord=?

acess 无密 string file
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=?
acess 有密 string file, string pwd
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=?;Jet OLEDB:Database Password=?


oracle  string ip, int port, string db, string user, string pwd
 "Data Source = ( DESCRIPTION =" +
                "( ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST=?)(PORT=?)))" +
                "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=?)));" +
                "User Id=?;Password=?;";
2011-10-27 17:47
快速回复:求C#连接数据库完整代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025025 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved