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
代码如下:
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
解决方案 »
- C# 多线程程序如何不会重复获取公共资源
- C#的word程序,“应用程序级项目”、“文档级项目”、“外接程序项目”有何区别
- 关于怎样读取文本文件到数据库
- session的问题
- 使用Access数据库,在创建表时定义一个“自动编号”和“数字”类型的“整型”字段时SQL语句如何写?
- ASP。NET页面按钮点击,不能触发C#中的CLICK事件。
- 图像显示问题
- 我的studio 里没有add-in 这个向导
- 初学C#用什么编译?
- 请问如何在pocket pc中用IE webbrowser控件
- 未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。
- 想到到脑筋锈钭的treeview更新问题!!
不过,这个错应该是编译的时候报的错吧
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"]);
}
}