C# Update语句不工作
所以我有一个SQL express服务器数据库。我有一份库存文件。我有一个语句插入新记录,另一个语句更新所有记录中的计数。第一个很好,但是我无法更新计数。我把每一句话都包装在自己的try,catch和not catch中。我在这里迷路了C# Update语句不工作,c#,sql,sql-server-2008,sql-server-express,C#,Sql,Sql Server 2008,Sql Server Express,所以我有一个SQL express服务器数据库。我有一份库存文件。我有一个语句插入新记录,另一个语句更新所有记录中的计数。第一个很好,但是我无法更新计数。我把每一句话都包装在自己的try,catch和not catch中。我在这里迷路了 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication8 { class Progra
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);
为什么不试着在catch块中放一些输出语句呢。它报告错误的可能性很大;但是,如果不对捕获的项目采取行动,您可能会丢掉它正在报告的问题 为什么不尝试在catch块中放入一些输出语句呢。它报告错误的可能性很大;但是,如果不对捕获的项目采取行动,您可能会丢掉它正在报告的问题 很有可能这是你代码中的一部分。如果您想让我们告诉您代码中的内容,您应该发布它,以便我们提供更具体的答案。update语句是否挂起?还是什么都不做就完成了?你提交插入了吗?这些语句是什么样子的?@Fatal我运行代码,它似乎可以工作。我检查数据库什么都没有当你用工具连接来检查结果时,你可能会使用不同的连接。当来自c#程序的DML未提交时,由于与ACID隔离,您将看不到新数据。你在你的程序中提交了你的事务吗?@Joe Tyman:既然你已经发布了代码,我就把它改为+1。很可能你的代码中有一些东西。如果您想让我们告诉您代码中的内容,您应该发布它,以便我们提供更具体的答案。update语句是否挂起?还是什么都不做就完成了?你提交插入了吗?这些语句是什么样子的?@Fatal我运行代码,它似乎可以工作。我检查数据库什么都没有当你用工具连接来检查结果时,你可能会使用不同的连接。当来自c#程序的DML未提交时,由于与ACID隔离,您将看不到新数据。你在你的程序中提交了你的事务吗?@Joe Tyman:既然你已经发布了代码,我就把它改成了+1。我在catch块上放了一个断点,什么也没抓住。我在catch块上放了一个断点,什么也没抓住。