I saw it possible on an msdn article. Actually I think it was
DataTable.NewRow method home page in its example. Now, I tried to create a
dataset with a table and 2 columns. When I ran the page I got this
problem:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 20: DataColumn IDColumn = new DataColumn("ID");
Line 21: IDColumn.DataType = Type.GetType("System.Int32");
Line 22: DataSet.Tables["Table"].Columns.Add(IDColumn);
Line 23: DataColumn ItemColumn = new DataColumn("Item");
Line 24: ItemColumn.DataType = typeof(String);
Source File: C:\Documents and Settings\Andy\My Documents\Visual Studio
2008\Projects\EternityRecordsWebsite\Contracts\WebForm1.aspx.cs Line:
22
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
Contracts.WebForm1.Page_Load(Object sender, EventArgs e) in
C:\Documents and Settings\Andy\My Documents\Visual Studio
2008\Projects\EternityRecordsWebsite\Contracts\WebForm1.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1436
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
How do I fix it? The references to DataType =
Type.GetType("System.Int32") and DataType=Typeof(String) were left that
way on purpose for trying to figure out the problem. I had both of the
columns datatype set to Typeof(...) but changed the IDColumns to
Type.GetType(...) when I originally got this problem. Any idea what the
problem is? Is it possible I can't add columns after the table is added
to the dataset?
Mark Rae said:
[top-posting corrected again]
It passes an object array (containing four elements) as the first
argument of the Add method of the datatable's Rows collection...
Is this the only way you can do it? or is there some other way.
Probably - there's usually more than one way to do most things in the
.NET Framework...
I used NewDataTableRow() before... is this possible without sql server?
Sorry, I don't know. I always use the method I outlined...