更新声明无效

时间:2011-06-06 18:54:09

标签: c# sql sql-server-2008 sql-server-express

所以我有一个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); 

1 个答案:

答案 0 :(得分:1)

为什么不尝试在catch块中放置一些输出语句。它报告错误的几率非常高;但是如果没有对被抓住的物品采取行动,你可能会丢掉它所报告的问题!