score:10
Accepted answer
The problem is that you didn't specify that your columns are int
s. You can specify that with the Add(string, Type)
method.
dt.Columns.Add("RowId", typeof(int));
dt.Columns.Add("Amount", typeof(int));
DataRow row = dt.NewRow();
// whether you add strings or ints here doesn't matter, it's converted
row[0] = "1";
row[1] = 2000;
Source: stackoverflow.com
Related Articles
- Error in LINQ to SQL: specified cast is not valid
- Linq result Int error: Specified cast is not valid
- LINQ union with BIT column causing Specified cast is not valid error
- Linq To Data set error System.InvalidCastException: Specified cast is not valid
- Specified cast is not valid Linq Query
- Linq To SQL - Specified cast is not valid - SingleOrDefault()
- Specified cast is not valid in linq query
- Insert throw error : Specified cast is not valid
- LINQ to List: Specified cast is not valid
- Linq to SQL: specified cast is not valid
- Linq Specified cast is not valid
- asp.net - Specified cast not valid Linq
- Linq Query Message: Specified cast is not valid
- LINQ Specified Cast is Not Valid with a ushort Table Column
- Linq to sql poco approach specified cast is not valid
- LINQ - Specified cast is not valid with dataview use
- Linq to dataset - Sum method - Specified cast is not valid
- specified cast is not valid in linq to sql
- Cast LINQ result to ObservableCollection
- The specified cast from a materialized 'System.Int32' type to the 'System.Double' type is not valid
- System.InvalidCastException: Specified cast is not valid. Error
- How to cast a Linq Dynamic Query result as a custom class?
- LINQ Source Code Available
- The specified cast from a materialized 'System.Int32' type to the 'System.Int64' type is not valid
- Linq to Sql, System.Exception cast is not valid
- Compiler error when using LINQ on IEnumerable<dynamic> but not if you cast it to IEnumerable<dynamic> first
- Cast a Linq result set to an interface
- Retrieve bool result by using LinQ code
- creating Linq to sqlite dbml from DbLinq source code
- LINQ: Specified Cast is not valid
- How can I filter object by child list property?
- Linq causes syntax error with Top (1)
- How to write this LINQ query to get a particular claim from Identity oauth
- sql to C# functional query
- Join, Group By and Aggregate with LINQ
- Linq query with multiple joins and groups
- Filter null properties from list using Linq
- WPF ObservableCollection : possible to modify one particular property on all items at once?
- How to Sort a List of Objects by dictionary value?
- Put LINQ query result to DataTable
- Getting wrong sum and count in linq
- Cannot use Exists function in anonymous list VB.net
- Linq to sql add/dynamic OR WHERE clause
- LINQ with list<int> quering the Value of a Dictonary<int, object>
- Linq to SQL - Find element with lowest field value - Performance
- What is from keyword in linq?
- How to sum a custom object with LinQ?
- Extracting data packet out of byte buffer
- Removing duplicates from Array with C#.NET 4.0 LINQ?
- Linq: List all Rows in DataGridView that contain at least 2 cells with a Value