Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add new Column

Status
Not open for further replies.

lutzs

Programmer
Oct 8, 2002
75
LU
Hi,

i will add a new column in my dataset.
Now, i get this error message:

An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll

Additional information: DataTable already belongs to this DataSet.

What can I do?

Thanks,
Stephanie
 
It seems that you are trying to add a table that is the same with a table you already have in the DataSet.
Could you post your code for adding the column in the dataset?
 
hi,

here's my code:

DataTable TestTable = new DataTable("TestTable");

DataColumn myDataColumn;

myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.Int32");
myDataColumn.ColumnName = "TestID";
myDataColumn.AllowDBNull = false;
myDataColumn.Unique = true;
myDataColumn.DefaultValue = 0;

TestTable.Columns.Add(myDataColumn);

DataColumn[] PK = new DataColumn[1];
PK[0] = TestTable.Columns["TestID"];
TestTable.PrimaryKey = PK;

DataRow newRow;
newRow = TestTable.NewRow();

newRow["TestID"] = 25;

TestTable.Rows.Add(newRow);

dataSet.Tables.Add(TestTable);

foreach(DataTable t in dataSet.Tables)
{
oRpt.SetDataSource (dataSet);
oRpt.SetDataSource (TestTable);

crystalReportViewer1.ReportSource = oRpt;
}

thanks,
Stephanie
 
Are you sure that you don't have another table named "TestTable" in your dataset when you are adding it? Are you sure that the method containing this code is not called twice with the same dataset, duplicating thus the table "TestTable"?
And if not, can you tell the exact line where the exception occurs?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top