简体   繁体   English

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

[英]Failed to convert parameter value from a string to int64

I'm getting an error : Failed to convert parameter from string to Int 64 here is the ligne : 我收到一个错误:无法将参数从字符串转换为Int 64,这里是ligne:

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

I already tried 我已经试过了

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()); 

My sql table contains NBC BigInt Any help would be appreciated. 我的sql表包含NBC BigInt将不胜感激。

What type of object does ligneGridDC1.Cells["NBcmd"] contain? ligneGridDC1.Cells [“ NBcmd”]包含什么类型的对象?

Calling .ToString() on an object will by default return the type of object, unless the ToString method has been overridden. 默认情况下,在对象上调用.ToString()将返回对象的类型,除非已重写ToString方法。 you're trying to convert 'SomeType.Cell' to a Int64. 您正在尝试将'SomeType.Cell'转换为Int64。

Try this... 尝试这个...

        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;

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM