导入数据库时​​,删除数据表中值的后两个字符

问题描述:

我在DataTable列中的值类似于"49102122011173902767-R".将其导入数据库时​​,使用C#.NET从DataTable中将其插入为"49102122011173902767".

任何人都可以帮助我.

在此先谢谢您.

I have a value similar to ''49102122011173902767-R'' in a DataTable column. When am importing it into DB, it gets inserted as ''49102122011173902767'' from DataTable using C#.NET.

Anyone help me please.

Thanks in advance.

很显然,您会遇到此问题.因为您在表的列中使用的数据类型为VARCHAR(20),并且您传递的长度为22.这就是为什么它转义字符串的最后两个字符的原因.只需增加列的大小即可.即从VARCHAR(20)VARCHAR(25).


祝一切顺利.
--Amit
Obviously, you''ll get this problem. Because the datatype which you are using in your table''s column is VARCHAR(20) and you are passing a value of length 22. That is why it is escaping last two chars of your string. Just increase the size of your column. i.e., from VARCHAR(20) to VARCHAR(25).


All the best.
--Amit




我想从前端做,然后使用子字符串.删除最后两个字符,然后保存到数据库中.

http://www.dotnetperls.com/substring [ http://msdn.microsoft.com/en-us/library/ms187748%28v = sql.90%29.aspx [ ^ ]

谢谢,
Viprat
Hi,

I you want to do from front end side then use substring. Remove last 2 characters and then save into DB.

http://www.dotnetperls.com/substring[^]

If you want to do from Back End then also you can use substring into your query.

http://msdn.microsoft.com/en-us/library/ms187748%28v=sql.90%29.aspx[^]

Thanks,
Viprat


您已给定varchar(20),因此它仅占用前20个字符.将列大小增加到50,然后尝试导入.
You have given varchar(20) so it is taking only first 20 characters. Increase the column size to 50 and try to import.