c#中,DataTable.Select()中括号里的参数的语法规则,是个什么样的? 本人新手,请教

 我来答
BraveHeart_Fov
2012-05-07 · TA获得超过7942个赞
知道小有建树答主
回答量:1037
采纳率:0%
帮助的人:679万
展开全部
Select(String)/Select(String, String)/Select(String, String, DataViewRowState)
private void GetRows()
{
// Get the DataTable of a DataSet.
DataTable table = DataSet1.Tables["Suppliers"];
DataRow[] rows = table.Select();

// Print the value one column of each DataRow.
for(int i = 0; i < rows.Length ; i++)
{
Console.WriteLine(rows[i]["CompanyName"]);
}
}
*****

private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > #1/1/00#";
DataRow[] foundRows;

// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression);

// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
****

private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];

// Presuming the DataTable has a column named Date.
string expression = "Date > '1/1/00'";

// Sort descending by column named CompanyName.
string sortOrder = "CompanyName DESC";
DataRow[] foundRows;

// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression, sortOrder);

// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
*****

private static void GetRowsByFilter()
{
DataTable customerTable = new DataTable("Customers");
// Add columns
customerTable.Columns.Add("id", typeof(int));
customerTable.Columns.Add("name", typeof(string));

// Set PrimaryKey
customerTable.Columns[ "id" ].Unique = true;
customerTable.PrimaryKey = new DataColumn[]
{ customerTable.Columns["id"] };

// Add ten rows
for(int id=1; id<=10; id++)
{
customerTable.Rows.Add(
new object[] { id, string.Format("customer{0}", id) });
}
customerTable.AcceptChanges();

// Add another ten rows
for(int id=11; id<=20; id++)
{
customerTable.Rows.Add(
new object[] { id, string.Format("customer{0}", id) });
}

string expression;
string sortOrder;

expression = "id > 5";
// Sort descending by column named CompanyName.
sortOrder = "name DESC";
// Use the Select method to find all rows matching the filter.
DataRow[] foundRows =
customerTable.Select(expression, sortOrder,
DataViewRowState.Added);

PrintRows(foundRows, "filtered rows");

foundRows = customerTable.Select();
PrintRows(foundRows, "all rows");
}

private static void PrintRows(DataRow[] rows, string label)
{
Console.WriteLine("\n{0}", label);
if(rows.Length <= 0)
{
Console.WriteLine("no rows found");
return;
}
foreach(DataRow row in rows)
{
foreach(DataColumn column in row.Table.Columns)
{
Console.Write("\table {0}", row[column]);
}
Console.WriteLine();
}
}

自己看看文档
http://technet.microsoft.com/zh-cn/library/system.data.datatable.select(v=vs.110)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lh8710
2012-05-07
知道答主
回答量:26
采纳率:0%
帮助的人:19.6万
展开全部
DataTable.Select() 括号里的为一个条件, 类似SQL的 where 条件
比如 DataTable中有字段A 查询 字段A等1的数据 可以用 DataTable.Select("A=1")
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wy2142010
2012-05-07 · TA获得超过175个赞
知道小有建树答主
回答量:257
采纳率:0%
帮助的人:144万
展开全部
1、select(string):
private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > #1/1/00#";
DataRow[] foundRows;

// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression);

// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
2、select(string,string)

private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];

// Presuming the DataTable has a column named Date.
string expression = "Date > '1/1/00'";

// Sort descending by column named CompanyName.
string sortOrder = "CompanyName DESC";
DataRow[] foundRows;

// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression, sortOrder);

// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
灬Asia__小神
2012-05-07 · TA获得超过152个赞
知道答主
回答量:119
采纳率:0%
帮助的人:85万
展开全部
vs 不是有提示吗 要么不加参数 要么加string 类型的参数
string 有什么语法规则啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式