DataSet读取数据时,有出错,
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.Sql;
namespace ConsoleDataSetTest
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection thisConnection = new SqlConnection(@"Data Source=WONDER_TAN_XP00;Initial Catalog=product;Persist Security Info=True;User ID=sa;Password=123");            SqlDataAdapter thisAdapter = new SqlDataAdapter("select * from userss",thisConnection);            productDataSet thisDataSet = new productDataSet();            thisAdapter.Fill(thisDataSet,"userss");            foreach (DataRow theRow in thisDataSet.Tables["userss"].Rows)
            {
                Console.WriteLine(theRow["id"]+"\t"+theRow["name"]);
            }
        }
    }
}
出错的信息是如下:
Error 1 The type or namespace name 'DataRow' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\agan_qin\My Documents\Visual Studio 2005\Projects\ConsoleDataSetTest\ConsoleDataSetTest\Program.cs 20 22 ConsoleDataSetTestError 2 Cannot apply indexing with [] to an expression of type 'DataRow' C:\Documents and Settings\agan_qin\My Documents\Visual Studio 2005\Projects\ConsoleDataSetTest\ConsoleDataSetTest\Program.cs 22 35 ConsoleDataSetTestError 3 Cannot apply indexing with [] to an expression of type 'DataRow' C:\Documents and Settings\agan_qin\My Documents\Visual Studio 2005\Projects\ConsoleDataSetTest\ConsoleDataSetTest\Program.cs 22 53 ConsoleDataSetTest

解决方案 »

  1.   

    没有引入System.Data;命名空间,所以系统不认识你的DataRow这个类,你可以像1楼说的那样做。或者在DataRow前面加上System.Data.DataRow
      

  2.   

    lz用的不是vs环境吗,这个对命名空间应该有智能感知的
      

  3.   

    加上Using System.Data;
    不过,这个错应该是编译的时候报的错吧
      

  4.   

    如果链接数据库没有错误的话,你可以改成这样-------
    static void Main(string[] args)
            {
                SqlConnection thisConnection = new SqlConnection(@"Data Source=WONDER_TAN_XP00;Initial Catalog=product;Persist Security Info=True;User ID=sa;Password=123");            SqlDataAdapter thisAdapter = new SqlDataAdapter("select * from userss", thisConnection);            //productDataSet thisDataSet = new productDataSet(); 
                System.Data.DataSet thisDataSet = new System.Data.DataSet();            thisAdapter.Fill(thisDataSet, "userss");            //foreach (DataRow theRow in thisDataSet.Tables["userss"].Rows)
                foreach (System.Data.DataRow theRow in thisDataSet.Tables["userss"].Rows)
                {
                    Console.WriteLine(theRow["id"] + "\t" + theRow["name"]);
                }
            }
      

  5.   

    引用using System.Data;命名空间就行了..1楼正解!
      

  6.   

    对啊,引入命名空间就好了!如果还不行的话,可以调试看看thisDataSet.Tables["userss"].Rows.Count 是不是有值。或者用thisDataSet.Tables0].Rows.Count 也可以!
      

  7.   

    引入 System.Data命名空间,