'dataType' argument cannot be null. Parameter name: dataType

having trouble adding a dynamic column to a datagrid, i keep getting this error.  I build all my columns on HTML side but i need to add these fields from my sql code, if I do it in code it slows down the query quite considerably, so I thought do it in DG instead.

'dataType' argument cannot be null. Parameter name: dataType

To me it seems its not getting my SQL code, what am I doing wrong.





myDataTable = New DataTable
myDataTable = getData(sql)
 
Dim dc As DataColumn
dc = New DataColumn("VAC2", Type.GetType("System.Integer"))
 dc.Expression = "myDataTable.Rows(0)(7) + myDataTable.Rows(0)(8) - myDataTable.Rows(0)(9)"
myDataTable.Columns.Add(dc)
 
myDataGrid.DataSource = myDataTable
myDataGrid.DataBind()

Open in new window

kdeutschAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

satheeshmCommented:
Hi

Try with Type.GetType("Int32") instead of Type.GetType("System.Integer")
0
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
As suggested by satheeshm, try using Int32 by passing System.Int32 in GetType.
See this EE link for possible solution on the same lines: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24406745.html
0
kdeutschAuthor Commented:
Hi,
Still get the same error.  It points to this line
dc = New DataColumn("VAC2", Type.GetType("Int32"))

Before the code shown above is my sql select statement
SQL = "Select fields from tblblah"   (its way to big for me to fit in here)

I am follwoing guidlines from multiple sites and don't understnad why this won't work for me.


0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

kdeutschAuthor Commented:
Ok,
Got past that error by changing to this, from link above.
dc = New DataColumn("VAC2", System.Type.GetType("System.Int32"))

but now i get this error that point sto next line.
The expression contains undefined function call myDataTable.Rows().
 dc.Expression = "myDataTable.Rows(0)(7) + myDataTable.Rows(0)(8) - myDataTable.Rows(0)(9)"
0
kdeutschAuthor Commented:
Hi,
this does not through any code exceptiosn but also does not show the new column in datagrid either.

 Dim dc As DataColumn = Nothing
dc = New DataColumn("VAC2", System.Type.GetType("System.Int32"))
dc.Expression = "AUTH_STR + OS - ASGN_STR"    (Column names from SQL code)
myDataTable.Columns.Add(dc)
0
satheeshmCommented:
you are using datatable as string. that should be like this.

dc.Expression = myDataTable.Rows(0)(7) + myDataTable.Rows(0)(8) - myDataTable.Rows(0)(9)

0
kdeutschAuthor Commented:
I see, but it still will not should the new datagrid column, when it shows the column is not there.
0
kdeutschAuthor Commented:
Hi,
I think I made mistake in adding to mydatatable instead of this
myDataGrid.Columns.Add(dc)
But I get a blue underline under the dc even though its asking me what to add.
0
satheeshmCommented:
I tried this, in my application now. its adding new column.

            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "SELECT * FROM Customers where customername like 'z%' and CompanyID = '" + strCompanyID + "'"
            cmd.Connection = conn
            Dim da As New SqlDataAdapter(cmd)
            Dim ds As New DataSet
            da.Fill(ds)
            Dim dt As New DataTable
            dt = ds.Tables(0)

            Dim dc As DataColumn
            dc = New DataColumn("VAC2", Type.GetType("System.Int32"))
            dc.Expression = dt.Rows(0)(6)
            dt.Columns.Add(dc)


            'Dim dr As SqlDataReader = cmd.ExecuteReader()
            GridView1.DataSource = dt
            GridView1.DataBind()

Can you check your code once again.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kdeutschAuthor Commented:
Ok, fianlly got back to this. its working now, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.