数据库是本地数据库,数据库名: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”的引用。 但是找了好多遍都没看到这个引用要怎么添加。。
谁 知道帮忙解决下。谢谢。
现在我用下面的代码来连接数据库:
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”的引用。 但是找了好多遍都没看到这个引用要怎么添加。。
谁 知道帮忙解决下。谢谢。
解决方案 »
- 请教 怎么在前台绑定虚拟路径下的图片
- C#中viewstate的工作原理是什么啊?
- winfrom中控件循环的问题,就是考试系统,循环出所有的题,每道题后边有ABCD选项,然后提交,怎么做?着急,等高手!
- RadAjax控件问题
- comboBox问题。。。
- winform 控件 anchor 属性 与 Dock属性的关系,
- 如何判断网页的更新?
- 求Rational XDE for .net下载(不能是电驴下载的连接,公司不充许用这个下。。。。。)
- 如何去掉excel的保存對話框
- 在C#中如何将一个窗体设为TopMost,置于顶的窗体,
- 如何获得路由器接入internet的外网ip地址?
- C#中如何实现远程注入代码或远程注入DLL
using System.ComponentModel;这个命名空间,但这个命名空间提供的是Component类,但这个类是做什么作用的呢。
//Component类提供 IComponent接口的基实现并启用应用程序之间的对象共享。他的派生类有:System.Data.Common.DbCommand 等
但是不是使用这个System.Data.Common.DbCommand 派生类就需要引用System.ComponentModel。Component基类????请问各位大虾解释下,谢谢。
不过我自己定义一个类using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices; // 调用 WINAPI 加载namespace FileWatcherLib
{
public class Listener : Component
...
......
这样继承的把我这个文件编译成dll 然后再引用
结果
FileWatcherLib.Listener lf;
定义的对象就报上面的错。???