当我给出返回数量时,它给出了输入字符串不正确格式的异常 [英] when i give return quantity so its gives exception that input string was not in correct formate

查看:78
本文介绍了当我给出返回数量时,它给出了输入字符串不正确格式的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mycode是在行下面的接受

mycode is acception accuring below line

private void dgDetail_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    if (dgDetail.CurrentRow != null)
    {
 
 
   int Unit =Convert.ToInt32(objDB.GetDataField("Select Unit from tblDescribeProduct Where Code ='" + dgDetail.CurrentRow.Cells["ProductCode"].Value.ToString() + "'", "Unit"));

please tell me problem

推荐答案

Hi Tahir,



你不能将字符串转换为Int,它只会在运行时识别。



这个错误有两种可能,比如

Hi Tahir,

You cannot convert string to Int, it will be identified only during the run time.

There are two possibilities for this error, like
int Unit= Convert.ToInt32(" "); and 

int Unit= Convert.ToInt32("1a");



如果你确定查询返回一个值,那么尝试使用Var代替

像这样


If you are sure that query returns a value then try using Var instead
like this

var Unit = objDB.GetDataField("Select Unit from tblDescribeProduct Where Code ='" + dgDetail.CurrentRow.Cells["ProductCode"].Value.ToString() + "'", "Unit");



希望这对你有所帮助。

在这里随意提出疑问。





此致,

RK


Hope this helps you a bit.
Feel free to raise any doubt here.


Regards,
RK


您必须准备
'" + dgDetail.CurrentRow.Cells["ProductCode"].Value.ToString() + "'", "Unit"

在Select Query之外的字符串,只使用Select语句使用该字符串变量如下所示,因此Sql server不知道。 ToString()



string outside the Select Query and use that string variable only withing the Select statement is as below,Hence Sql server doesn't know about the .ToString()

Select Unit from tblDescribeProduct Where (Code = strValue)


这篇关于当我给出返回数量时,它给出了输入字符串不正确格式的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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