插入数据的问题。 [英] Issue with Inserting data.

查看:72
本文介绍了插入数据的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013.我开发了一个应用程序并进行了部署。如果用户创建新记录。我使用visual studio代码插入一条新记录。用户输入他们想要为其创建新记录的序列号。如果他们输入123456
,我的插入查询会很好地插入它。如果他们输入3K1234,则会出错,说明"K1234"附近存在"语法不正确"。所以我查看了Sql Express表中的字段。它的数据类型是nvarchar(50)。我打开了SSMS并创建了一个insert语句,
能够插入值3K1234。然后我回到Visual Studio中的应用程序。我调试了应用程序并捕获了我的查询,如果我正在插入123456,它会构建以下查询。注意:我也在初始化其他一些值。

I am using Visual Studio 2013. I developed an application and have deployed it. If a user creates a new record. I Insert a new record using visual studio code. The user enters a serial number that they want to create a new record for. If they enter 123456 my Insert query inserts it just fine. If they enter 3K1234 it errors out stating there is "Incorrect Syntax near 'K1234'. So I looked at the field in my Sql Express table. Its data type is nvarchar(50). I opened SSMS and created an insert statement and was able to insert the value 3K1234. I then went back to my application in Visual Studio. I debugged the application and captured my query if I am Inserting 123456 it builds the following query. Note: I am also initializing some other values.


" INSERT INTO tMtrSo_tblWidgets(ESN,[Record Date],[Test Issues],[正在进行的工作],[商业讨论],[不添加数据],[不添加低时间],[免除],[EngDI],
[合同TAT],[延迟天数])值(12345 ,'4/24/2019 10:58:36 AM',0,0,0,0,0,0,0,0,0);"



以上工作正常。



如果我输入 


" INSERT INTO tMtrSo_tblWidgets(ESN,[记录日期],[测试问题],[在制品],[商业讨论],[不添加数据],[不添加低时间],[豁免],[EngDI],
[合同TAT],[延迟天数])值(3K1234,'4/24/2019 10:58:36 AM',0,0,0,0,0,0 ,0,0,0);"



它给了我上面提到的错误。我正在祈祷某人对我的问题有一个答案。它让我发疯。请提前感谢任何帮助。


推荐答案

您在TSQL中分隔字符串单引号。

You delimit strings in TSQL with single quote.

因此,假设ESN是字符串类型,您的命令应该是:

So, assuming ESN is a string type, your command should be:

INSERT INTO tMtrSo_tblWidgets (ESN, [Record Date], [Test Issues], [Work In Process], [Commercial Discussion], [Do Not Add Data], [Do Not Add Low Time], [Exempt], [EngDI], [Contract TAT], [Delay Days]) Values ('3K1234','4/24/2019 10:58:36 AM', 0, 0, 0, 0, 0, 0, 0, 0, 0);


这篇关于插入数据的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆