DataColumn Add

Posted on 2011-04-30
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

    Try using

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

    Accepted Solution

    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.

    LVL 4

    Author Closing Comment

    the explicit declaration of the column was key

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now