请帮我解决这个问题,数据表对数据库的价值 [英] please Help me to solve this issue datatable value to database

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

问题描述


以下是我用于向数据库输入数据表值的代码
我从变量doId1
中获取这个DoNumber值中总共有4个字段

Hi
Below is my code for entering data table value to database
totally i have 4 fields in this DoNumber value i am taking from the variable doId1

foreach (string item in sc)
        {
            const string insertsql = "INSERT INTO Items(DoNumber,ItemNo,Description,Qty)VALUES (";
            sb.AppendFormat("{0}", insertsql);
            if (item.Contains(","))
            {
                splitItems = item.Split(",".ToCharArray());
                sb.AppendFormat("{0},'{1}','{2}''{3}');", doId1, splitItems[0], splitItems[1], splitItems[2]);


            }
        }



这就是我在Stringbuilder中得到的值



this is the value what i am getting in Stringbuilder

{INSERT INTO Items(DoNumber,ItemNo,Description,Qty)VALUES (2011002-DO,''2'',''vcjj''''2'');}



我的错误讯息是

在这种情况下,不允许使用名称"DO".有效表达式是常量,常量表达式和(在某些情况下)变量.不允许使用列名.>

请帮我解决这个问题

谢谢



My error msg is

The name "DO" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.>

Pls help me to resolve this

Thanks

推荐答案



试试这个:

Hi,

Try this:

const string insertsql = "INSERT INTO Items(DoNumber,ItemNo,Description,Qty) VALUES ('";
            sb.AppendFormat("{0}", insertsql) + "'";



如果需要帮助,请不要忘记投票...



Please don''t forget to vote if help...

Regards,


我注意到了两件事.您为什么在这里的第3个值和第4个值之间没有逗号:
Two things I''ve noticed. Why don''t you have a comma between the 3rd and 4th values here:
sb.AppendFormat("{0},''{1}'',''{2}''''{3}'');", doId1, splitItems[0], splitItems[1], splitItems[2]);


另外,由于值不是数字,为什么还没有{0}呢?

这两个都可能引起问题,但是我认为第二个问题是错误消息的原因.不过,您可能需要同时修复这两个问题.


And also why don''t you have '' around {0} since the value is not a number?

Both of these are probably causing issues, but I think the second issue is the cause of the error message. You probably need to fix both though.


sb.AppendFormat("{0},'{1}','{2}''{3}');", doId1, splitItems[0], splitItems[1], splitItems[2])


change into


change into

sb.AppendFormat("'{0}','{1}','{2}','{3}');", doId1, splitItems[0], splitItems[1], splitItems[2])


这篇关于请帮我解决这个问题,数据表对数据库的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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