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

问题描述

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

推荐答案

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)


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

09-09 15:14