string inserttest = "UPDATE Warranty([LenovoBaseWarrantyStartDate], [LenovoBaseWarrantyEndDate], [LenovoBaseWarrantyStatus])"
+ "VALUES (@LenovoBaseWarrantyStartDate, @LenovoBaseWarrantyEndDate, @LenovoBaseWarrantyStatus)";
OleDbCommand cmd = new OleDbCommand(inserttest, conn1);
OleDbCommand accessCommand = conn1.CreateCommand();
accessCommand.CommandText = ("SELECT SerialNumber from Warranty");
OleDbDataReader accessReader = accessCommand.ExecuteReader();
int count = accessReader.FieldCount;
List<StoreClass> storeList = new List<StoreClass>();
while (accessReader.Read())
{
for (int i = 0; i < count; i++)
{
string result = accessReader.GetValue(i).ToString();
webBrowser1.Document.GetElementById("serialCode").Focus();
webBrowser1.Document.GetElementById("serialCode").InnerText = result;
webBrowser1.Document.GetElementById("warrantySubmit").InvokeMember("Click");
Thread.Sleep(500);
MessageBox.Show("Serial Number:" + " " + result);
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div"))
if (el.GetAttribute("className") == "fluid-row Borderfluid")
{
string record = el.InnerText;
var result1 = parseString(record);
string StartDate = string.Join("", result1.ConvertAll(r => string.Format("{0}", r)).ToArray());
DateTime strStartDate = DateTime.ParseExact(StartDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
string EndDate = string.Join("", result1.ConvertAll(r => string.Format("{1}", r)).ToArray());
DateTime strEndDate = DateTime.ParseExact(EndDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
string Status = string.Join("", result1.ConvertAll(r => string.Format("{2}", r)).ToArray());
bool strStatus = "Active" == "1" && "Expired" == "0";
storeList.Add(new StoreClass(strStartDate, strEndDate, strStatus));
cmd.Parameters.Add("@LenovoBaseWarrantyStartDate", OleDbType.Date).Value = storeList[0].startDate;
cmd.Parameters.Add("@LenovoBaseWarrantyEndDate", OleDbType.Date).Value = storeList[0].endDate;
cmd.Parameters.Add("@LenovoBaseWarrantyStatus", OleDbType.Boolean).Value = storeList[0].status;
cmd.Parameters.Add("@LenovoWarrantyUpgradeStartDate", OleDbType.Date).Value = storeList[1].startDate;
cmd.Parameters.Add("@LenovoWarrantyUpgradeEndDate", OleDbType.Date).Value = storeList[1].endDate;
cmd.Parameters.Add("@LenovoWarrantyUpgradeStatus", OleDbType.Boolean).Value = storeList[1].status;
cmd.Parameters.Add("@LenovoPrioritySupportStartDate", OleDbType.Date).Value = storeList[2].startDate;
cmd.Parameters.Add("@LenovoPrioritySupportEndDate", OleDbType.Date).Value = storeList[2].endDate;
cmd.Parameters.Add("@LenovoPrioritySupportStatus", OleDbType.Boolean).Value = storeList[2].status;
//...
}
//...
}
//...
}
对不起代码墙,但是它可以让你知道我想弄清楚什么。我有这个循环来检索数据并将其存储到数据库表中。我正在尝试编辑顶部的 inserttest 语句,以便我可以更新当前正在循环的特定序列号中的列。
有没有办法做到这一点?我不能Update Warranty ... Where SerialNumber = result
因为它只存在于循环中(除非我可以而且我不知道如何)。
答案 0 :(得分:2)
您将其作为另一个参数传递,并添加where子句
WHERE SerialNumber = @result