要用 using System.Data.SqlClient 才行

解决方案 »

  1.   

    system.data下有sql?只要引用了system.data就可以了吧
      

  2.   

    用了system.data是不是以包括了system.data.***了,就算这样还是不能通过
    D:\vc-work\net\sjk1\Form1.cs(39): 找不到类型或命名空间名称“SQLDataSetCommand”(是否缺少 using 指令或程序集引用?)
      

  3.   

    using System.Data.SqlClient;
    应该是SqlCommand吧
      

  4.   

    using System.Data.SqlClient引入这个命名空间才行using System.Data只是引入了System.Data命名空间里的类,不会引用System.Data命名空间里的SqlClient命名空间里的类,所以要加上上面那句.
      

  5.   

    不是了,我是看了c#程序设计教程里写的一段联接数据库的代码(是不是联接sql7的呀),代码如下:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlTypes;
    using System.Data.Common;
    using System.Data.OleDb;
    using System.Data.SqlClient;namespace sjk1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    /// 

    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.ListBox listBox1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    string sConn = "server=192.168.1.6;uid=sa;pwd=;database=northwind";
    string sCommand = "select firstname,lastname from employees order by employeeid";
    SqlCommand DSCmd = new SqlCommand(sCommand, sConn);
    DataSet ds = new DataSet();
    DSCmd.FillDataSet(ds, "Employees");
    DataTable dt = ds.Tables[0];

    foreach(DataRow dr in dt.Rows)
    {
    listBox1.Items.Add(dr["firstname"] + "" + dr["lastname"]);
    } } /// <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.listBox1 = new System.Windows.Forms.ListBox();
    this.SuspendLayout();
    // 
    // listBox1
    // 
    this.listBox1.ItemHeight = 12;
    this.listBox1.Location = new System.Drawing.Point(32, 80);
    this.listBox1.Name = "listBox1";
    this.listBox1.Size = new System.Drawing.Size(120, 88);
    this.listBox1.TabIndex = 0;
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.listBox1});
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    }
    }
    }
    有一点是我改过的了,我只想简单的返回数据极了,练习当中,我是做asp的,想用c#来开发asp.net不知该如何下手?有什么好书推荐么?
    多谢了!!
      

  6.   

    你安装VS.NET后,在所有程序->Microsoft .NET Framework SDK中有一个网页链接:示例与快速入门教程。在这里面又很多关于ASP.NET的示例还有它的简单教程(比较全面)。
    你上面的例子是Windows Form的,要在ASP.NET中使用只需把初构函数中的连接数据库的代码拷过去就行了,另外你可以把Dataset对象绑定Datagrid控件上完成显示。