'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?
 
satheeshmConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
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
 
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
 
kdeutschAuthor Commented:
Ok, fianlly got back to this. its working now, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.