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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRowCollection .CopyTo

Status
Not open for further replies.

ousoonerjoe

Programmer
Jun 12, 2007
925
US
I am trying to copy a DataRow from one DataTable to another. In standard MSDN Help File fashion, when duplicating what is depicted, it doesn't work.
Code:
[COLOR=navy](MSDN Help File Syntax)
Dim instance As DataRowCollection
Dim array As DataRow()
Dim index As Integer

instance.CopyTo(array, index)[/color]
Code:
	Private Sub dgTrunk_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles dgTrunk.UserDeletedRow
		Dim Pop As clsSql = Nothing
		Dim dView As DataView = Nothing
		Dim dTab As DataTable = Nothing
		Dim CmbTab As DataSet = Nothing
		Dim dRow As DataRow()
		CmbTab = cmbStages.DataSource
		If Pop Is Nothing Then Pop = New clsSql
		Pop.CommandString = "cst_Select_AsyLineStages"
		Pop.AddParam("@AsyLineId", cmbAsyLine.SelectedValue)
		dTab = Pop.OpenDataTable
		dView = dTab.DefaultView
		dView.RowFilter = "StageId = " & e.Row.Cells(0).Value
		[COLOR=red]dView.Table.Rows.CopyTo(dRow, 0)[/color]
		CmbTab = cmbStages.DataSource
		CmbTab.Tables(0).Rows.Add(dRow(0))
		cmbStages.DataSource = CmbTab
	End Sub
The red line above returns the error:
'array' argument cannot be null.
Parameter name: array


What am i missing here? All i want to do is take the filtered result set from the DataView and add it to the CmbTab that will be bound to a combo box.

Any assistance is highly appreciated. Thank you.

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
you only declare the object
Code:
Dim dRow As DataRow()

without instatiating to any x-dimension array.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top