日期:2014-05-19  浏览次数:20735 次

ado.net连接数据库问题,为什么还需要
数据库是本地数据库,数据库名:goto63net   数据库中表名:userinfo  
现在我用下面的代码来连接数据库:
1.先添加对Syste.Data的引用
写了如下代码:
using   System;
using   System.Data;                    
using   System.Data.SqlClient;    
public   class   SqlData
{
        public   static   void   Main()
        {

                SqlConnection   thisConnection   =   new   SqlConnection(@ "Data   Source=local;   Initial   Catalog=goto63net;uid=sa;password=sa ");   //先建立连接
                thisConnection.Open();//打开连接
                SqlCommand   thisCommand   =   thisConnection.CreateCommand();
                thisCommand.CommandText   =   "SELECT   user_id   from   userinfo ";
                SqlDataReader   thisReader   =   thisCommand.ExecuteReader();
                //sqldatareader不可以用new   必须直接与command关联
                while   (thisReader.Read())
                {
                        Console.WriteLine( "\t{0} ",   thisReader[ "CustomerID "]);
                }
                        thisReader.Close();
                        thisConnection.Close();
        }
}

这里提示错误是:
类型“System.ComponentModel.Component”在未被引用的程序集中定义。必须添加对程序集“System,   Version=2.0.0.0,   Culture=neutral,PublicKeyToken=b77a5c561934e089”的引用。

但是找了好多遍都没看到这个引用要怎么添加。。
谁   知道帮忙解决下。谢谢。

------解决方案--------------------
没碰到过,学习下