ASP.NET MVC - System.Data.DataSet未引用的问题 [英] ASP.NET MVC - System.Data.DataSet not referenced problem

查看:471
本文介绍了ASP.NET MVC - System.Data.DataSet未引用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对于这个问题,首先对于这个问题一定很直接,但是我正在为自己奋斗,我需要让它工作:(
我正试图使用我的应用程序中的DataSet



当我呈现时,我得到:

 System.Data.DataSet类型在未引用的程序集中定义,您必须添加对程序集System.Data 

$的引用b
$ b

在我的应用程序中System.Data已经从C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll



我正在使用我的使用子句

  using System; 
使用System.Collections.Generic;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;

这个DataSet是Webservice的一个响应
所以任何关于如何解决这个问题的想法? / p>

PS不知道是否有帮助,但我正在使用nHaml来呈现我的观点



非常感谢






更新:



现在我发现的唯一解决方案是将DataSet传递给视图转换器DataSet到

 < List< List< String>> 

,并通过整个DataSet循环,如下

 列表<列表< String>> myList = new List< List< String>>(); 

foreach(dsTrades.Tables中的DataRow行[0] .Rows)
{
列表< String> myListColumns = new List< String>();

for(var index = 0; index< dsTrades.Tables [0] .Columns.Count; index ++)
{
myListColumns.Add(row [index] .ToString());
}

myList.Add(myListColumns);
}

//这应该是数据并且现在
//它转换为列表列表中
viewModel.Trades = myList;

return View(viewModel);

其实这是完全疯狂的吗?



如果直接使用DataSet,所有这些工作都可以很容易地完成。
我希望有人能用更简单的方法来帮助我。



谢谢:)






更新(解决方案)



Simon的答案非常有效,并且在为System.Data和System.Xml添加命名空间后首次尝试,但同时,Josh的答案提供了一个非常好的和酷的方式来处理DataSets,我的意见工作得更好,我想现在我会去。



感谢您的帮助

解决方案

尝试在您的nhaml配置中添加对System.Data的明确引用

  ;?xml version =1.0?> 

< configuration>
...
< configSections>
< section name =nhamltype =NHaml.Configuration.NHamlConfigurationSection,NHaml/>
< / configSections>
...
< nhaml autoRecompile =true>
< assembly>
< clear />
...
< add assembly =System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089/>
< / assemblies>
< namespaces>
< clear />
...
< add namespace =System.Data/>
< / namespaces>
< / nhaml>



显然替换... 你的其他参考和配置


Well, first of all sorry about this question it must be pretty straight forward for you guys but I'm struggling myself on it, and I need to make it work :( Well I'm trying t o use DataSet on my application

and when I render it I got:

The type 'System.Data.DataSet' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data

in my application System.Data is already being referenced from C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll

and I'm using on my using clauses as well

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

This DataSet is a response from a Webservice So any Ideas on how to fix this problem?

PS. I don't know if it helps, but I'm using nHaml to render my view

Thanks a lot


UPDATE:

The only solution I found for now was to instead passing a DataSet to the view converter the DataSet to a

<List<List<String>>

and pass a loop through the entire DataSet like this

List<List<String>> myList = new List<List<String>>();

foreach (DataRow row in dsTrades.Tables[0].Rows)
{
    List<String> myListColumns = new List<String>();

    for (var index = 0; index < dsTrades.Tables[0].Columns.Count; index ++)
    {
        myListColumns.Add(row[index].ToString());
    }

    myList.Add(myListColumns);
}

// THIS SHOULD BE THE DATASET AND NOW 
// IT'S CONVERTED TO A LIST WITH STRINGS LIST INSIDE
viewModel.Trades = myList; 

return View(viewModel);

Actually this is completely crazy ins't it?

All this job could be easily done into the view if using DataSet directly I hope anyone can help me with a more simplistic way to do it

Thank you :)


UPDATE (SOLUTION)

Simon's answer was really effective and it worked on the first try after adding namespaces for System.Data and System.Xml but at the same time, Josh's answer present a very nice and cool way to work with DataSets, which on my opinion works much better and I think I'll go for it now.

Thanks for you help

解决方案

try adding an explicit reference to System.Data in your nhaml configuration

<?xml version="1.0"?>

<configuration>
...
    <configSections>
            <section name="nhaml" type="NHaml.Configuration.NHamlConfigurationSection, NHaml"/>
    </configSections>
...
<nhaml autoRecompile="true">
            <assemblies>
                    <clear/>
                    ...
                    <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            </assemblies>
            <namespaces>
                    <clear/>
                    ...
                    <add namespace="System.Data"/>
            </namespaces>
    </nhaml>

obviously replacing "..." with your other references and config

这篇关于ASP.NET MVC - System.Data.DataSet未引用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆