循环后零位置没有行
本文关键字:位置 循环 | 更新日期: 2023-09-27 18:16:04
我需要以下帮助:
foreach (DataRow dr in dt.Rows)
{
PrepareDocument(dr);
}
//update table entries to processed state
try
{
string constring = "........";
string Query = @"update OnSiteWorkTx set Processed = 1 where VisitNumber = @company and Processed = 0";
using (SqlConnection conDatabase = new SqlConnection(constring))
using (SqlCommand cmdDatabase = new SqlCommand(Query, conDatabase))
{
cmdDatabase.Parameters.AddWithValue("@company", MyVariable);
conDatabase.Open();
cmdDatabase.ExecuteNonQuery();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
在PrepareDocument
中,我有以下内容:
private void PrepareDocument(DataRow dr)
{
string connectWrk = ".............";
using (SqlConnection connWrk = new SqlConnection(connectWrk))
{
string queryWrk = "SELECT Workdone FROM OnSiteWorkTx where VisitNumber='" + MyVarible + "' ";
SqlCommand cmdWrk = new SqlCommand(queryWrk, connWrk);
var ds = new DataSet();
var da = new SqlDataAdapter(cmdWrk);
da.Fill(ds);
var Workdone = ds.Tables[0].Rows[0]["Workdone"];
try
{
connWrk.Open();
tableWrk.AddCell(cellWrk);
tableWrk.AddCell(Workdone.ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
将表项更改为已处理状态的代码在Preparedocument(dr)
之前运行,则语句找不到已处理的表项现在为True,并且给出错误的位置0处没有行
尝试如下:
if (ds.Tables.Count > 0 && ds.Tables.Rows.Count > 0)
{
var Workdone = ds.Tables[0].Rows[0][0];
...