DataSet ds = new DataSet();
string ID = Request.QueryString["ID"].ToString();
if (Session["typeTable"] != null)
{
ds = (DataSet)Session["typeTable"];
DataRow[] drs = ds.Tables[0].Select("ID=17");
DataTable dt1 = new DataTable();
foreach (DataRow drs1 in drs)
{
dt1.ImportRow(drs1);
}
Label2.Text = dt1.Rows[0]["txt"].ToString();
我想这样获取值的时候提示我txt不属于dt1,我就换成
Label2.Text = dt1.Rows[0][0]ToString();
他有说无法找到列0
谁能告诉我怎么回事啊 或者有什么更加好的方法
string ID = Request.QueryString["ID"].ToString();
if (Session["typeTable"] != null)
{
ds = (DataSet)Session["typeTable"];
DataRow[] drs = ds.Tables[0].Select("ID=17");
DataTable dt1 = new DataTable();
foreach (DataRow drs1 in drs)
{
dt1.ImportRow(drs1);
}
Label2.Text = dt1.Rows[0]["txt"].ToString();
我想这样获取值的时候提示我txt不属于dt1,我就换成
Label2.Text = dt1.Rows[0][0]ToString();
他有说无法找到列0
谁能告诉我怎么回事啊 或者有什么更加好的方法
好点的可以用LINQvar result =
from a in ds.Tables[0].AsEnumerable()
where a.Field<string>("ID") == "17"
select a;
string query="ID"+ID;
DataRow[] drs = ds.Tables[0].Select(query);
Label2.Text = drs[0].Table.Rows[0]["txt"].ToString();
可是出来的结果却不应该出现在drs中的结果。我ID=17
drs里应该只有一行结果的。
有txt这个列吗?
dt1 = ds.Tables[0].Clone();//使用ImportRow要确定目标table和源table的结构一致
//使用ImportRow添加行
string ID = Request.QueryString["ID"].ToString();
if (Session["typeTable"] != null)
{
ds = (DataSet)Session["typeTable"];
DataRow[] drs = ds.Tables[0].Select("ID=17"); Label2.Text = drs[0]["txt"].ToString();
http://www.mybuffet.cn
我感觉是这句话,
DataRow[] drs = ds.Tables[0].Select("ID=17");
[1] "asdfsdfsdf" object {string}
[2] "成套设备" object {string}
+ [3] {2009-11-16 16:48:39} object {System.DateTime}
[4] "images/05.jpg" object {string}
[5] "yuiyui" object {string}
值是有的 这个是断点出来的结果,但是取值的时候就是不对啊
foreach(DataColumn dc in ds.Tables[0].Columns)
{
dt1.Columns.Add(new DataColumn(dc.ColumnName));
}
foreach (DataRow drs1 in drs)
{
dt1.ImportRow(drs1);
}
DataRow[] drs = ds.Tables[0].Select("ID=17"); DataTable dt1 = ds.Tables[0].Clone(); //克隆一下
.....就哦了