Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将参数值从字符串转换为int64_C#_Sql_Sql Server - Fatal编程技术网

C# 无法将参数值从字符串转换为int64

C# 无法将参数值从字符串转换为int64,c#,sql,sql-server,C#,Sql,Sql Server,我收到一个错误:无法将参数从字符串转换为Int 64 这是ligne: com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = ligneGridBC1.Cells["NBcmd"].ToString(); 我已经试过了 com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = Convert.ToInt64(ligneGridBC1.Cells["NBcmd"].ToString()); co

我收到一个错误:无法将参数从字符串转换为Int 64 这是ligne:

com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = ligneGridBC1.Cells["NBcmd"].ToString();
我已经试过了

com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = Convert.ToInt64(ligneGridBC1.Cells["NBcmd"].ToString());

com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = Int64.Parse(ligneGridBC1.Cells["NBcmd"].ToString()); 
我的sql表包含
NBC BigInt

任何帮助都将不胜感激。

ligneGridDC1.Cells[“NBcmd”]包含什么类型的对象

默认情况下,对对象调用.ToString()将返回对象的类型,除非已重写ToString方法。您正在尝试将“SomeType.Cell”转换为Int64

试试这个

        Int64 a = 0;
        if(!Int64.TryParse(ligneGridBC1.Cells["NBcmd"].ToString(), out a))
            throw new InvalidCastException(ligneGridBC1.Cells["NBcmd"].ToString());
        com.Parameters.Add("@NBC", SqlDbType.BigInt).Value = a;

希望有帮助

您是否检查了
ligneGridBC1.Cells[“NBcmd”].ToString()的值
?Convert.ToInt64(ligneGridBC1.Cells[“NBcmd”]);检查ligneGridBC1.Cells[“NBcmd”]是否返回空字符串,如果返回空字符串,则会发生此错误。如果单元格值为null或空,请尝试将默认值保持为0。