如何在基于xml的数据集SELECT方法中进行转换? [英] How to cast in an xml based dataset SELECT method?

查看:59
本文介绍了如何在基于xml的数据集SELECT方法中进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候。


我的情况:


//我有一个.xml文件,我正在读入<数据集中的

以下代码 -


DataSet ds = new DataSet(" MyDataset");

ds.ReadXml(@" c :\ data \" + cmyxmlfilename);


//然后我试图获取该数据集的一个子集来过滤

数据为如下:


DataSet subSet = ds.Clone();


DataRow [] copyRows = ds.Tables [1] .Select(" ;`myStringField` 19.99");


DataTable myTable = subSet.Tables [1];


foreach(copyRows中的DataRow copyRow)

{

myTable.ImportRow(copyRow);


}


我的问题:

当您以这种方式读取XML文件时,如何将列

转换为SELECT过滤器表达式的另一种类型?

例如,myStringField包含实际上是double的内容;,但是在

字符串格式中,因为XMLRead方法不允许您键入

结果字段。如何在使用ReadXML从XML创建的

数据集中转换SE​​LECT过滤器表达式?我试图在数据集ds中输出数据列的类型

,但它错误地说明我不能

在有数据后更改它数据集....好吧,鸡肉或鸡蛋

flambe?如何在SELECT过滤器之前转换列类型

表达式?或者Select方法中是否有一种方法可以调用演员?

我无法找到一种可行的方法。


提前谢谢,


Peter Robbins

哦,.NET很容易......如果你知道怎么做的话。

Greetings.

My Situation:

// I have an .xml file that I am reading into a dataset in the
following code -

DataSet ds = new DataSet("MyDataset");
ds.ReadXml(@"c:\data\"+cmyxmlfilename);

// I am then attempting to obtain a subset of that dataset to filter
the data as follows -

DataSet subSet = ds.Clone();

DataRow[] copyRows = ds.Tables[1].Select("`myStringField` 19.99");

DataTable myTable = subSet.Tables[1];

foreach (DataRow copyRow in copyRows)
{
myTable.ImportRow(copyRow);

}

My Question:
When you read an XML file in this manner, how do you cast the columns
to another type for a SELECT filter expression?

For example, myStringField contains what is actually a "double", but in
string format, as the XMLRead method doesn''t allow you to type the
resulting fields. How do I cast in a SELECT filter expression on a
dataset created from XML using ReadXML? I''ve attempted to cast the type
of the datacolumn in dataset "ds", but it errors out stating I cannot
change it after there is data in the dataset.... well, chicken or egg
flambe? How do I cast the column type prior to the SELECT filter
expression? Or is there a way in the Select method to call upon a cast?
I could not figure out a method that would work.

Thanks ahead of time,

Peter Robbins
"Oh, .NET is easy....... if you know how to do it".

推荐答案

嗨Peter,


1.创建一个强类型数据集并将模式定义为你想要它或者在运行之前将Typed列添加到DataSet中

读取数据。

2.'''myStringField''不应该在你的字符串中引用传递给Select方法,因为它指的是列名,而

不是字符串文字:选择(" myStringField 19.99")

3.而不是克隆你的DataSet,调用Select,循环结果并填充克隆,你可能最好使用

a DataView并设置RowFilter属性。


- -

Dave Sexton


" MurdockSE" < mu ***** @ nc.rr.com在留言新闻中写道:11 ********************* @ m79g2000cwm.googlegro ups.com ...
Hi Peter,

1. Create a strong-Typed DataSet and define the schema as you want it or add the Typed columns to your DataSet at runtime before
reading the data.
2. ''myStringField'' should not be quoted in the string you are passing to the Select method since it''s referring to a column name and
not a string literal: Select("myStringField 19.99")
3. Instead of cloning your DataSet, calling Select, looping through the results and filling the clone, you might be better off using
a DataView and setting the RowFilter property.

--
Dave Sexton

"MurdockSE" <mu*****@nc.rr.comwrote in message news:11*********************@m79g2000cwm.googlegro ups.com...

问候。


我的情况:


//我有一个.xml文件,我正在读取

中的数据集代码 -


DataSet ds = new DataSet(" MyDataset");

ds.ReadXml(@" c:\data \" + cmyxmlfilename);


//然后我尝试获取该数据集的子集过滤

数据如下 -


DataSet subSet = ds.Clone();


DataRow [ ] copyRows = ds.Tables [1] .Select("``myStringField` 19.99");


DataTable myTable = subSet.Tables [1];


foreach(copyRows中的DataRow copyRow)

{

myTable.ImportRow(copyRow);


}


我的问题:

当您以这种方式阅读XML文件时,如何投射列

另一种类型的SELECT过滤器表达式?


例如,myStringField包含的实际上是double,但是在

字符串格式中,作为XMLRead方法不允许您键入

结果字段。如何在使用ReadXML从XML创建的

数据集中转换SE​​LECT过滤器表达式?我试图在数据集ds中输出数据列的类型

,但它错误地说明我不能

在有数据后更改它数据集....好吧,鸡肉或鸡蛋

flambe?如何在SELECT过滤器之前转换列类型

表达式?或者Select方法中是否有一种方法可以调用演员?

我无法找到一种可行的方法。


提前谢谢,


Peter Robbins

哦,.NET很容易......如果你知道怎么做的话。
Greetings.

My Situation:

// I have an .xml file that I am reading into a dataset in the
following code -

DataSet ds = new DataSet("MyDataset");
ds.ReadXml(@"c:\data\"+cmyxmlfilename);

// I am then attempting to obtain a subset of that dataset to filter
the data as follows -

DataSet subSet = ds.Clone();

DataRow[] copyRows = ds.Tables[1].Select("`myStringField` 19.99");

DataTable myTable = subSet.Tables[1];

foreach (DataRow copyRow in copyRows)
{
myTable.ImportRow(copyRow);

}

My Question:
When you read an XML file in this manner, how do you cast the columns
to another type for a SELECT filter expression?

For example, myStringField contains what is actually a "double", but in
string format, as the XMLRead method doesn''t allow you to type the
resulting fields. How do I cast in a SELECT filter expression on a
dataset created from XML using ReadXML? I''ve attempted to cast the type
of the datacolumn in dataset "ds", but it errors out stating I cannot
change it after there is data in the dataset.... well, chicken or egg
flambe? How do I cast the column type prior to the SELECT filter
expression? Or is there a way in the Select method to call upon a cast?
I could not figure out a method that would work.

Thanks ahead of time,

Peter Robbins
"Oh, .NET is easy....... if you know how to do it".



非常感谢。我会尝试你在#3中提到的。我认为

这是一种更好的方法。另外,在#2中,那些是单左蜱,而不是单引号(b)键盘上的标记,而不是

引号下的双引号ENTER)我使用它们,因为我使用的很多

字段的列名都有空格。我只是没有使用名称在列名中没有

空格的名称从这个例子中移除



此致,


彼得


Dave Sexton写道:
Thank you very much. I will attempt what you mention in #3. I think
that is a better method. Also, in #2, those are single left ticks, not
single quotes (the mark under the tilde on the keyboard as opposed to
the quote under the double quotes near ENTER) I use them as many of the
fields I use have whitespace in their column names. I just had not
removed them from this example using a name that does not have
whitespace in the column name.

Regards,

Peter

Dave Sexton wrote:

彼得,


1.创建一个强类型DataSet并根据需要定义模式,或者在运行之前将Typed列添加到DataSet中

读取数据。

2.''myStringField''不应该在你传递给Select方法的字符串中引用,因为它指的是列名和

not字符串文字:选择(" myStringField 19.99")

3.您可能最好使用

a DataView并设置RowFilter属性。


-

Dave Sexton


" MurdockSE" < mu ***** @ nc.rr.com在留言新闻中写道:11 ********************* @ m79g2000cwm.googlegro ups.com ...
Hi Peter,

1. Create a strong-Typed DataSet and define the schema as you want it or add the Typed columns to your DataSet at runtime before
reading the data.
2. ''myStringField'' should not be quoted in the string you are passing to the Select method since it''s referring to a column name and
not a string literal: Select("myStringField 19.99")
3. Instead of cloning your DataSet, calling Select, looping through the results and filling the clone, you might be better off using
a DataView and setting the RowFilter property.

--
Dave Sexton

"MurdockSE" <mu*****@nc.rr.comwrote in message news:11*********************@m79g2000cwm.googlegro ups.com...

问候。


我的情况:


//我有一个.xml文件,我正在读取

中的数据集代码 -


DataSet ds = new DataSet(" MyDataset");

ds.ReadXml(@" c:\data \" + cmyxmlfilename);


//然后我尝试获取该数据集的子集过滤

数据如下 -


DataSet subSet = ds.Clone();


DataRow [ ] copyRows = ds.Tables [1] .Select("``myStringField` 19.99");


DataTable myTable = subSet.Tables [1];


foreach(copyRows中的DataRow copyRow)

{

myTable.ImportRow(copyRow);


}


我的问题:

当你以这种方式阅读XML文件时,你如何c对于SELECT过滤器表达式,列为

到另一种类型?


例如,myStringField包含的实际上是double,但在

字符串格式,因为XMLRead方法不允许您键入

结果字段。如何在使用ReadXML从XML创建的

数据集中转换SE​​LECT过滤器表达式?我试图在数据集ds中输出数据列的类型

,但它错误地说明我不能

在有数据后更改它数据集....好吧,鸡肉或鸡蛋

flambe?如何在SELECT过滤器之前转换列类型

表达式?或者Select方法中是否有一种方法可以调用演员?

我无法找到一种可行的方法。


提前谢谢,


Peter Robbins

哦,.NET很容易......如果你知道怎么做的话。
Greetings.

My Situation:

// I have an .xml file that I am reading into a dataset in the
following code -

DataSet ds = new DataSet("MyDataset");
ds.ReadXml(@"c:\data\"+cmyxmlfilename);

// I am then attempting to obtain a subset of that dataset to filter
the data as follows -

DataSet subSet = ds.Clone();

DataRow[] copyRows = ds.Tables[1].Select("`myStringField` 19.99");

DataTable myTable = subSet.Tables[1];

foreach (DataRow copyRow in copyRows)
{
myTable.ImportRow(copyRow);

}

My Question:
When you read an XML file in this manner, how do you cast the columns
to another type for a SELECT filter expression?

For example, myStringField contains what is actually a "double", but in
string format, as the XMLRead method doesn''t allow you to type the
resulting fields. How do I cast in a SELECT filter expression on a
dataset created from XML using ReadXML? I''ve attempted to cast the type
of the datacolumn in dataset "ds", but it errors out stating I cannot
change it after there is data in the dataset.... well, chicken or egg
flambe? How do I cast the column type prior to the SELECT filter
expression? Or is there a way in the Select method to call upon a cast?
I could not figure out a method that would work.

Thanks ahead of time,

Peter Robbins
"Oh, .NET is easy....... if you know how to do it".


嗨Peter,


啊,是的。 #2应该被忽视;)


-

Dave Sexton


" MurdockSE" < mu ***** @ nc.rr.com在留言新闻中写道:11 ********************** @ i3g2000cwc.googlegro ups.com .. 。
Hi Peter,

Ahh yes. #2 should be disregarded ;)

--
Dave Sexton

"MurdockSE" <mu*****@nc.rr.comwrote in message news:11**********************@i3g2000cwc.googlegro ups.com...

非常感谢。我会尝试你在#3中提到的。我认为

这是一种更好的方法。另外,在#2中,那些是单左蜱,而不是单引号(b)键盘上的标记,而不是

引号下的双引号ENTER)我使用它们,因为我使用的很多

字段的列名都有空格。我只是没有使用名称在列名中没有

空格的名称从这个例子中移除



此致,


彼得


Dave Sexton写道:
Thank you very much. I will attempt what you mention in #3. I think
that is a better method. Also, in #2, those are single left ticks, not
single quotes (the mark under the tilde on the keyboard as opposed to
the quote under the double quotes near ENTER) I use them as many of the
fields I use have whitespace in their column names. I just had not
removed them from this example using a name that does not have
whitespace in the column name.

Regards,

Peter

Dave Sexton wrote:

> Hi彼得,

1。创建一个强类型DataSet并根据需要定义模式,或者在读取数据之前在运行时将Typed列添加到DataSet中。
2。 ''myStringField''不应该在你传递给Select方法的字符串中引用,因为它指的是列名

不是字符串文字:Select(" myStringField 19.99" ;)
3。而不是克隆你的DataSet,调用Select,循环结果并填充克隆,你可能最好使用DataView并设置RowFilter属性。

-
Dave Sexton

MurdockSE < mu ***** @ nc.rr.com在留言新闻中写道:11 ********************* @ m79g2000cwm.googlegro ups.com ...
>Hi Peter,

1. Create a strong-Typed DataSet and define the schema as you want it or add the Typed columns to your DataSet at runtime before
reading the data.
2. ''myStringField'' should not be quoted in the string you are passing to the Select method since it''s referring to a column name
and
not a string literal: Select("myStringField 19.99")
3. Instead of cloning your DataSet, calling Select, looping through the results and filling the clone, you might be better off
using
a DataView and setting the RowFilter property.

--
Dave Sexton

"MurdockSE" <mu*****@nc.rr.comwrote in message news:11*********************@m79g2000cwm.googlegro ups.com...

问候。


我的情况:


//我有一个.xml文件,我正在读取

中的数据集代码 -


DataSet ds = new DataSet(" MyDataset");

ds.ReadXml(@" c:\data \" + cmyxmlfilename);


//然后我尝试获取该数据集的子集过滤

数据如下 -


DataSet subSet = ds.Clone();


DataRow [ ] copyRows = ds.Tables [1] .Select("``myStringField` 19.99");


DataTable myTable = subSet.Tables [1];


foreach(copyRows中的DataRow copyRow)

{

myTable.ImportRow(copyRow);


}


我的问题:

当您以这种方式阅读XML文件时,如何投射列

另一种类型的SELECT过滤器表达式?


例如,myStringField包含的实际上是double,但是在

字符串格式中,作为XMLRead方法不允许您键入

结果字段。如何在使用ReadXML从XML创建的

数据集中转换SE​​LECT过滤器表达式?我试图在数据集ds中输出数据列的类型

,但它错误地说明我不能

在有数据后更改它数据集....好吧,鸡肉或鸡蛋

flambe?如何在SELECT过滤器之前转换列类型

表达式?或者Select方法中是否有一种方法可以调用演员?

我无法找到一种可行的方法。


提前谢谢,


Peter Robbins

哦,.NET很容易......如果你知道怎么做的话。
Greetings.

My Situation:

// I have an .xml file that I am reading into a dataset in the
following code -

DataSet ds = new DataSet("MyDataset");
ds.ReadXml(@"c:\data\"+cmyxmlfilename);

// I am then attempting to obtain a subset of that dataset to filter
the data as follows -

DataSet subSet = ds.Clone();

DataRow[] copyRows = ds.Tables[1].Select("`myStringField` 19.99");

DataTable myTable = subSet.Tables[1];

foreach (DataRow copyRow in copyRows)
{
myTable.ImportRow(copyRow);

}

My Question:
When you read an XML file in this manner, how do you cast the columns
to another type for a SELECT filter expression?

For example, myStringField contains what is actually a "double", but in
string format, as the XMLRead method doesn''t allow you to type the
resulting fields. How do I cast in a SELECT filter expression on a
dataset created from XML using ReadXML? I''ve attempted to cast the type
of the datacolumn in dataset "ds", but it errors out stating I cannot
change it after there is data in the dataset.... well, chicken or egg
flambe? How do I cast the column type prior to the SELECT filter
expression? Or is there a way in the Select method to call upon a cast?
I could not figure out a method that would work.

Thanks ahead of time,

Peter Robbins
"Oh, .NET is easy....... if you know how to do it".



这篇关于如何在基于xml的数据集SELECT方法中进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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