访问数据库的问题。在线等待,马上送高分 using system.dataorimports system.dataor在菜单上选引用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你们上面的回答只是一个声明,好象还要把system.data.dll这个程序集添加到项目的references文件夹中。怎么添加? to:psxfghost(哈哈) 只是取出sqlserver数据库里的数据 To zhendexiangni(初学者) : 你不是要添加System.Data.dll吗?选择你创建的那个项目,找到references那个文件夹点击右键,选择添加引用再对话框的.net标签页中找到System.Data.dll选择然后,确定就可以添加System.Data.dll的引用了:)给分 to:dragontt(龙人) 在解决方案资源管理器中没有看到references这个文件夹怎么办? 引用只要using System.Data.SqlClient;但不知你是不是只要加System.Data.dll,是的话,楼上的已经答了,就结贴,如不是就把代码贴出来看看。 vs.net中的工程名下,右上角。 在引用上单击右键,选添加引用,在.Net选项卡中选择System.Data.dll,点击“选择”then 点击“确定”。 using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;namespace WindowsApplication6{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.StatusBar sb; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.TreeView tv; private System.Windows.Forms.Panel panel1; private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; private System.Data.SqlClient.SqlCommand sqlDeleteCommand1; private System.Data.SqlClient.SqlConnection sqlConnection1; private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2; private System.Data.SqlClient.SqlCommand sqlSelectCommand2; private System.Data.SqlClient.SqlCommand sqlInsertCommand2; private System.Data.SqlClient.SqlCommand sqlUpdateCommand2; private System.Data.SqlClient.SqlCommand sqlDeleteCommand2; private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter3; private System.Data.SqlClient.SqlCommand sqlSelectCommand3; private System.Data.SqlClient.SqlCommand sqlInsertCommand3; private System.Data.SqlClient.SqlCommand sqlUpdateCommand3; private System.Data.SqlClient.SqlCommand sqlDeleteCommand3; private WindowsApplication6.dsNorthwind dsNorthwind1; private System.ComponentModel.IContainer components; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.sb = new System.Windows.Forms.StatusBar(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.tv = new System.Windows.Forms.TreeView(); this.panel1 = new System.Windows.Forms.Panel(); this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlDataAdapter2 = new System.Data.SqlClient.SqlDataAdapter(); this.sqlDeleteCommand2 = new System.Data.SqlClient.SqlCommand(); this.sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand(); this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand2 = new System.Data.SqlClient.SqlCommand(); this.sqlDataAdapter3 = new System.Data.SqlClient.SqlDataAdapter(); this.sqlDeleteCommand3 = new System.Data.SqlClient.SqlCommand(); this.sqlInsertCommand3 = new System.Data.SqlClient.SqlCommand(); this.sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand3 = new System.Data.SqlClient.SqlCommand(); this.dsNorthwind1 = new WindowsApplication6.dsNorthwind(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dsNorthwind1)).BeginInit(); this.SuspendLayout(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3, this.menuItem4, this.menuItem5, this.menuItem6}); this.menuItem1.Text = "数据(&D)"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "检索数据(&Q)"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Index = 1; this.menuItem3.Text = "保存数据(&S)"; // // menuItem4 // this.menuItem4.Index = 2; this.menuItem4.Text = "显示雇员信息(&E)"; // // menuItem5 // this.menuItem5.Index = 3; this.menuItem5.Text = "-"; // // menuItem6 // this.menuItem6.Index = 4; this.menuItem6.Text = "退出(&X)"; // // sb // this.sb.Location = new System.Drawing.Point(0, 359); this.sb.Name = "sb"; this.sb.Size = new System.Drawing.Size(456, 22); this.sb.TabIndex = 0; this.sb.Text = "就绪"; // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(16, 16); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // tv // this.tv.Dock = System.Windows.Forms.DockStyle.Fill; this.tv.ImageList = this.imageList1; this.tv.Name = "tv"; this.tv.Size = new System.Drawing.Size(152, 359); this.tv.TabIndex = 1; // // panel1 // this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] { this.tv}); this.panel1.Dock = System.Windows.Forms.DockStyle.Left; this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(152, 359); this.panel1.TabIndex = 4; // // sqlDataAdapter1 // this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1; this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1; this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1; this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), To zhendexiangni(初学者): 你说的那种状况不会出现啦,用C#开发的项目都会有一个references啦除非你不是用vs.net这种工具而采用命令行方式的话用下面这种方式csc /reference System.Data.dll ...具体内容,你参看ms-help://MS.VSCC/MS.MSDNVS.2052/cscomp/html/vcrefcsharpcompileroptionsbycategory.htm 检查你的SQL语句,我也碰见过类似的问题,查了好久结果是SQL语句错了点点。 To zhendexiangni(初学者):像System.Data.dll IDE缺省就把它带进去了,不需要额外添加引用。你可以尝试着自己调试一下程序。比如。1)运行,看看那一行出错。2)用try catch 抓出错误来,看看到底出了什么错误。try{...//这是你出错的code}catch(Exception ex){MessageBox.Show(ex.ToString());}3)像大家说的那样,把SQL语句单独拿到Sql query 那样的tools中专门执行一下。 socket问题 求助:C#的简单问题 运用ExcecuteScalar方法时出错,帮忙改正啊! C#线程问题。。。。。。 代码中连接FTP后进行操作,帮改一下代码 为什么表单提交后汉字丢失了? 几个简单的窗口样式问题 如何让TreeView的一个节点呈选择状态(获得焦点,而不是复选状态) 请教:为什么点击button后代码不执行? 请问大虾,如何在Datagird或其他格式中,显示汇总数据和分类汇总数据。 请教winform中使用时间控件 请教指针的问题
只是取出sqlserver数据库里的数据
你不是要添加System.Data.dll吗?选择你创建的那个项目,找到references那个文件夹
点击右键,选择添加引用
再对话框的.net标签页中找到System.Data.dll
选择
然后,确定
就可以添加System.Data.dll的引用了
:)
给分
在解决方案资源管理器中没有看到references这个文件夹怎么办?
但不知你是不是只要加System.Data.dll,是的话,楼上的已经答了,就结贴,
如不是就把代码贴出来看看。
在.Net选项卡中选择System.Data.dll,点击“选择”
then 点击“确定”。
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.StatusBar sb;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.TreeView tv;
private System.Windows.Forms.Panel panel1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2;
private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
private System.Data.SqlClient.SqlCommand sqlInsertCommand2;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand2;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter3;
private System.Data.SqlClient.SqlCommand sqlSelectCommand3;
private System.Data.SqlClient.SqlCommand sqlInsertCommand3;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand3;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand3;
private WindowsApplication6.dsNorthwind dsNorthwind1;
private System.ComponentModel.IContainer components; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.sb = new System.Windows.Forms.StatusBar();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.tv = new System.Windows.Forms.TreeView();
this.panel1 = new System.Windows.Forms.Panel();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter2 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter3 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand3 = new System.Data.SqlClient.SqlCommand();
this.dsNorthwind1 = new WindowsApplication6.dsNorthwind();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dsNorthwind1)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem6});
this.menuItem1.Text = "数据(&D)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "检索数据(&Q)";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "保存数据(&S)";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "显示雇员信息(&E)";
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "-";
//
// menuItem6
//
this.menuItem6.Index = 4;
this.menuItem6.Text = "退出(&X)";
//
// sb
//
this.sb.Location = new System.Drawing.Point(0, 359);
this.sb.Name = "sb";
this.sb.Size = new System.Drawing.Size(456, 22);
this.sb.TabIndex = 0;
this.sb.Text = "就绪";
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// tv
//
this.tv.Dock = System.Windows.Forms.DockStyle.Fill;
this.tv.ImageList = this.imageList1;
this.tv.Name = "tv";
this.tv.Size = new System.Drawing.Size(152, 359);
this.tv.TabIndex = 1;
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tv});
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(152, 359);
this.panel1.TabIndex = 4;
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"),
new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
你说的那种状况不会出现啦,用C#开发的项目都会有一个references啦除非你不是用vs.net这种工具
而采用命令行方式的话
用下面这种方式
csc /reference System.Data.dll ...
具体内容,你参看
ms-help://MS.VSCC/MS.MSDNVS.2052/cscomp/html/vcrefcsharpcompileroptionsbycategory.htm
比如。
1)运行,看看那一行出错。
2)用try catch 抓出错误来,看看到底出了什么错误。
try
{
...//这是你出错的code
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
3)像大家说的那样,把SQL语句单独拿到Sql query 那样的tools中专门执行一下。