English 中文(简体)
在数据库中更新时丢出 Sql 例外
原标题:Updating in database throws SqlException

以下是我的SQL声明:

UPDATE InboxItem 
SET OrderId = @0, Item = @1, Quantity = @2, Price = @3, 
    Memo = "", InboxId = @4, VATId = @5 
WHERE Id = @6

这将抛出 Sql Explition , 上面写着

An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

我想我知道问题在于什么。如果我给梅莫以价值,一切都会好起来。然而,我有时希望备忘录是空字符串。如何做到这一点?

最佳回答

使用 而不是 " 。 同时验证输入是否正确( 可能其中一条字符串中有一个逗号是不可避免的) 。

问题回答
var sb = new StringBuilder();            
sb.Append("UPDATE InboxItem ");
sb.Append("SET OrderId = @0, Item = @1, Quantity = @2, Price = @3, ");
sb.Append("Memo = @7, InboxId = @4, VATId = @5 ");
sb.Append("WHERE Id = @6");
var cm = new SqlCommand(sb.ToString());
cm.CommandType = System.Data.CommandType.Text;
cm.Parameters.AddWithValue("@1", Convert.ToInt16("OrderValue"));
//and so on




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签