I have a datatable with One ColumnName \"CustomerID\" with Integer DataType. Dynamically I want to add rows to the DataTable. For that, I had created one DataRow object like:
DR["CustomerID"] = !string.IsNullOrEmpty(TextBox1.Text) ? Convert.ToInt32(TextBox1.Text) : DBNull.Value;
But you should check also that the value is a valid integer:
int value; if(int.TryParse(TextBox1.Text, out value)) { DR["CustomerID"] = value; } else { DR["CustomerID"] = DBNull.Value; }