Bilal
Bilal

Reputation: 1

Specific cast not valid

I use Linq-to-SQL to insert data 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

Upvotes: 0

Views: 1358

Answers (2)

Reactor
Reactor

Reputation: 99

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

Upvotes: 2

hunter
hunter

Reputation: 63512

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.

Upvotes: 0

Related Questions