2011-06-06 49 views
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); 
+2

请张贴您的代码。 – Asaph 2011-06-06 18:55:22

+0

赔率很好,这是你的代码中的东西。如果您希望我们告诉您代码中的内容,请将其发布,以便我们提供更具体的答案。 – 2011-06-06 18:57:30

+0

更新语句是否挂起?还是没有做任何事情就完成了?你有没有提交插入? 这些陈述是什么样子的? – 2011-06-06 18:58:29

回答

1

你为什么不尝试把一些输出语句在你的catch块。报告错误的可能性非常好;但是如果没有处理被捕获的物品,你可能会抛弃它正在报告的问题!

+0

我在catch块放了一个断点,没有任何东西可以捕捉到。 – 2011-06-06 19:05:57