如何在`存储过程中转换此对话? [英] How do I convert this conversation in `stored procedure?

查看:81
本文介绍了如何在`存储过程中转换此对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Data.SqlClient.SqlException:将varchar值'Churc'转换为数据类型int时转换失败



我尝试过:



我试图从int转换为varchar,但我不知道如何在存储过程中只转换一个#ID。

System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value 'Churc' to data type int

What I have tried:

I tried to convert from int to varchar but i have no idea how to convert only one #ID in stored procedure.

推荐答案

当您尝试转换的值不包含整数值时,会出现此错误:可能是字母前缀,或者是日期,或者某人的电子邮件地址 - 我们不知道知道,我们无法找到,因为我们根本无法访问您的数据!



因此,首先查看您的数据并确切了解其中的内容列,适用于所有行。如果你在VARCHAR列中存储数值,那么这是一个很大的错误,你需要改变你的数据库设计 - 因为这会一次又一次地反复咬你。
You get this error when the value you are trying to convert does not contain an integer value: maybe is has a alphabetic prefix, or it's a date, or perhaps someone's email address - we don't know and we can't find out because we have no access to your data at all!

So start by looking at your data and find out exactly what is in the column, for all rows. If you are storing numeric values in VARCHAR columns, then that's a big mistake and you need to change your DB design - because this will come back to bite you over and over again.


没有看到存储过程的实际代码和了解您的应用程序特定需求,很难告诉您解决问题的最佳方法。



过去,我已经使用这两种SQL Server工具来克服类似的问题

TRY_CONVERT [ ^ ]

TRY ... CATCH< [ ^ ]
Without seeing the actual code of the Stored Procedure and knowing your applications specific needs, it is kind if hard to tell you the best way to fix the problem.

In the past, I have used both of these SQL Server tools to overcome similar problems
TRY_CONVERT[^]
TRY...CATCH<[^]


这篇关于如何在`存储过程中转换此对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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