标题:数据库连接问题
取消只看楼主
caroal
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-10-1
 问题点数:0 回复次数:0 
数据库连接问题
我是一名新秀,刚学C#,在连接数据库的时候老师出错,望指点,连接代码如下:
 SqlConnection thisConnection = new SqlConnection(
                @"Server=(local);Integrated Security=True;" +
                "Database=northwind");
            //打开连接
            thisConnection.Open();
            //创建命令
            SqlCommand thisCommand = thisConnection.CreateCommand();
            //查询语句
             =
                "SELECT CustomerID ,CompanyName from Customers";
            //执行DataReader
            SqlDataReader thisReader = thisCommand.ExecuteReader();
            //while there are rows to read
            while (thisReader.Read())
            {
                //输出ID 和 NAME 行
                Console.WriteLine("\t{0}\t{1}",
                    thisReader["CustomerID"], thisReader["CompanyName"]);
            }
            //关闭 Reader
            thisReader.Close();
            //关闭连接
            thisConnection.Close();
            Console.WriteLine("Programe finished ,press enter/return to continue");
            Console.ReadKey();
搜索更多相关主题的帖子: 数据库 新秀 thisCommand Custom 
2008-02-24 15:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-200768-1-1.html




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

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