1
所以我有一個SQL Express服務器數據庫。我有一個庫存文件。我有一條語句插入新記錄,另一條語句用於更新所有記錄中的計數。第一個工作正常,但我不能讓計數更新。我將這些陳述中的每一個都包裝在自己的嘗試中,趕上並且它沒有抓住。我在這裏很迷路。更新聲明不起作用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
string[] lines = System.IO.File.ReadAllLines(@"C:\out\b.txt");
//System.Console.WriteLine("Contents of writeLines2.txt =:");
int i = 0;
foreach (string line in lines)
{
string sellername, sku, date1, quantity1, date2, asin, date3, date4, FNSKU;
char[] tabs = { '\t' };
string[] words = line.Split(tabs);
sku = words[0];
FNSKU = words[1];
asin = words[2];
quantity1 = words[5];
Console.WriteLine("\t" + line);
inventoryBLL u = new inventoryBLL();
try
{
u.AddToDatabase(sku, DateTime.Now, Convert.ToInt16(0), DateTime.Now, 0, asin, DateTime.Now, DateTime.Now, FNSKU);
}
catch
{ }
try
{
u.UpdateDatabase(sku, quantity1);
}
catch
{ }
foreach (string s in words)
{
System.Console.WriteLine(s);
}
++i;
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
這裏是BLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication8.DataSet1TableAdapters;
namespace ConsoleApplication8
{
[System.ComponentModel.DataObject]
class inventoryBLL
{
private AmazonSKUsTableAdapter _skuAdapter = null;
protected AmazonSKUsTableAdapter Adatper
{
get
{
if (_skuAdapter == null)
_skuAdapter = new AmazonSKUsTableAdapter();
return _skuAdapter;
}
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Insert, false)]
public void AddToDatabase(string sku, DateTime date, int quantity, DateTime date1, int quantity1, string asin, DateTime date2, DateTime date3, string FNSKU)
{
Adatper.AddToDatabase("A1B7M9EQGNCLQA", sku, date, quantity, date1, quantity1, asin, date2, date3, FNSKU);
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Update, false)]
public void UpdateDatabase(string sku, string quality)
{
Adatper.UpdateQuery(Convert.ToInt16(quality), sku);
}
}
}
下面是該查詢:
UPDATE AmazonSKUs
SET TotalQty = @TotalQty
WHERE (MerchantSKU = @Original_MerchantSKU);
請張貼您的代碼。 – Asaph 2011-06-06 18:55:22
賠率很好,這是你的代碼中的東西。如果您希望我們告訴您代碼中的內容,請將其發佈,以便我們提供更具體的答案。 – 2011-06-06 18:57:30
更新語句是否掛起?還是沒有做任何事情就完成了?你有沒有提交插入? 這些陳述是什麼樣子的? – 2011-06-06 18:58:29