本文介绍了如何在SQL Express数据库中获取行的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在使用C#和SQL Express.我需要获取行的当前位置,然后在当前位置更新数据.
该怎么做..?
这是我的代码:
Hi All,
I am using C# and SQL Express. I need to get the row current position and then to update a data at current position.
How to do this..?
Here is my code :
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Name", con);
DataSet ds = new DataSet();
da.Fill(ds, "Name");
foreach (DataRow dr in ds.Tables["Name"].Rows)
{
Console.WriteLine(dr["FirsName"] + "\t" + dr["NickName"] + "\t" + dr["Address"] + "\t" + dr["Gender"]);
//Console.Write(ds.Rows.position);
//int RowIndex = ds.Rows.position;
//SqlCeCommand Cmd = new SqlCeCommand("UPDATE Name SET Gender = 'Male' where ds.Rows.position ='" + RowIndex +"'", con);
//Cmd.ExecuteNonQuery();
Console.Write("Press Enter to continue:");
Console.ReadLine();
}
有帮助吗?
谢谢
Any Help??
Thanks
推荐答案
da.Fill(ds, "Name");
int iRowCount = 0;
foreach (DataRow dr in ds.Tables["Name"].Rows)
{
++iRowCount;
Console.WriteLine(dr["FirsName"] + "\t" + dr["NickName"] + "\t" + dr["Address"] + "\t" + dr["Gender"]);
// Do your stuff here.
// Current row index is: iRowCount
}
或
Or
da.Fill(ds, "Name");
foreach (DataRow dr in ds.Tables["Name"].Rows)
{
Console.WriteLine(dr["FirsName"] + "\t" + dr["NickName"] + "\t" + dr["Address"] + "\t" + dr["Gender"]);
// Do your stuff here.
// Current row index is: ds.Tables["Name"].Rows.IndexOf(dr)
}
这篇关于如何在SQL Express数据库中获取行的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!