开发者

Specific cast not valid

开发者 https://www.devze.com 2023-02-25 15:16 出处:网络
I use Linq-to-SQL to insert data开发者_如何学Python in vb.net. When I insert data into SQL Server through a DataGridView it gives error of which column data type is \"integer\" but when I insert data

I use Linq-to-SQL to insert data开发者_如何学Python in vb.net. When I insert data into SQL Server through a DataGridView it gives error of which column data type is "integer" but when I insert data through textbox it not give any error

So I face problem of datatype "integer" to error of specific cast not valid


Well,

There are a few ways to convert a string to an int. But for a safe conversion I would go int.TryParse(your_string_value, out result_value)

This will give you the chance to handle none int values in a more graceful manner.

Good Luck


Try using CType

someObject.IntegerProperty = CType(myTextBox.Value, Int32)

CType Function

Returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号