【发布时间】:2011-05-31 06:36:03
【问题描述】:
我有这段代码来创建新的 sql 表 当我执行此操作时,它会显示屏幕截图上的此错误。在我的数据库中没有这样的表。它显示此错误的任何表名。谁能帮帮我?
public void Create(string TName, string ConString)
{
try
{
using (SqlCommand cmd = new SqlCommand("CREATE TABLE [dbo].['" + TName + "']("
+ "[ID] [int] IDENTITY(1,1) NOT NULL,"
+ "[DateTime] [date] NOT NULL,"
+ "[BarCode] [nvarchar](max) NOT NULL,"
+ "[ArtNumber] [nvarchar](max) NOT NULL,"
+ "[ProductName] [nvarchar](50) NOT NULL,"
+ "[Quantity] [int] NOT NULL,"
+ "[SelfPrice] [decimal](18, 2) NOT NULL,"
+ "[Price] [decimal](18, 2) NOT NULL,"
+ "[Disccount] [int] NULL,"
+ "[Comment] [nvarchar](max) NULL,"
+ "CONSTRAINT ['" + TName + "'] PRIMARY KEY CLUSTERED "
+ "("
+ "[ID] ASC"
+ ")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"
+ ") ON [PRIMARY]", new SqlConnection(ConString)))
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
}
catch (Exception)
{
throw;
}
}
【问题讨论】:
-
您的“折扣”列命名错误,除非您打算将其命名为“折扣”。在英文中,“折扣”中只有一个“c”。
-
顺便说一句,+1 用于显示代码和确切的错误消息。这应该是如何在这里提出问题的主要示例。
标签: c# sql-server winforms