DataColumn Add

Posted on 2011-04-30
Medium Priority
Last Modified: 2012-06-21
I have this statement where custDs is the dataset I populate and then am trying to add a column of string type to the


but im getting this error on runtime,any ideas since my syntax or order is

System.ArgumentNullException: 'dataType' argument cannot be null. Parameter name: dataType at System.Data.DataColumn..ctor(String columnName, Type dataType, String expr, MappingType type) at System.Data.DataColumnCollection.Add(String columnName, Type type) at ASP.moiz_aspx.Button1_Click(Object sender, EventArgs e)


				Dim sqlstring as String ="select * from persons"

	Dim sql1command as sqlcommand 
				sql1command = new sqlcommand(sqlstring,cn)
				Dim custDA As SqlDataAdapter = New SqlDataAdapter("select * from persons", cn)
				Dim custDS As DataSet = New DataSet()

				custDA.Fill(custDS, "persons")

Open in new window

Question by:Moizsaif123
LVL 83

Expert Comment

ID: 35497876
Try using

custds.tables(0).Columns.Add("Total", GetType(String))
LVL 10

Accepted Solution

Asim Nazir earned 400 total points
ID: 35499263
Column should be decimal if it's total but string shold work also.
Here is snippet from MSDN:

DataTable table = new DataTable("Product");

    // Create a DataColumn and set various properties.
    DataColumn column = new DataColumn();
    column.DataType = System.Type.GetType("System.Decimal");  
// make it "System.String" for string
   column.AllowDBNull = false;
    column.Caption = "Price";
    column.ColumnName = "Price";
    column.DefaultValue = 25;

    // Add the column to the table.

Details: http://msdn.microsoft.com/en-us/library/system.data.datacolumn(v=VS.100).aspx

Author Closing Comment

ID: 35500557
the explicit declaration of the column was key

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question