datagrid/dataset question

lovesirius12

New member
Joined
Dec 3, 2006
Messages
4
Programming Experience
1-3
hi. i hope you could help me with my problem.

i need to import to a dataset the contents of an unbound datagrid. how do you think i could do that? please help! thanks.
 
hi. i've already found the answer, through msdn of course. and just to share it. here's the code i used.


VB.NET:
Private Sub S_PutValue(ByVal ds As DataSet)
' Get Each DataTable in the DataTableCollection and 
' print each row value.
Dim intTotalRow As Integer = Me.dgv_Payment.RowCount - 2
Dim intTotalColumn As Integer = 7
Dim x As Integer = 0
Dim y As Integer = 0
 
For x = 0 To intTotalRow
Dim strSupplierRecord As DataRow = ds.Tables("tblPayment").NewRow()
y = 0
strSupplierRecord("Supplier_Code") = Me.dgv_Payment.Item(y, x).Value
y += 1
strSupplierRecord("Supllier_Name") = Me.dgv_Payment.Item(y, x).Value
y += 1
strSupplierRecord("Period") = Me.dgv_Payment.Item(y, x).Value
y += 1
strSupplierRecord("Sales_Of_Event") = CDbl(Me.dgv_Payment.Item(y, x).Value)
y += 1
strSupplierRecord("Haigac_Of_Event") = CDbl(Me.dgv_Payment.Item(y, x).Value)
y += 1
strSupplierRecord("Event_Rate") = CDbl(Me.dgv_Payment.Item(y, x).Value)
y += 1
strSupplierRecord("Consumption_Tax") = CDbl(Me.dgv_Payment.Item(y, x).Value)
y += 1
strSupplierRecord("Amount_Of_Money_Payment") = CDbl(Me.dgv_Payment.Item(y, x).Value)
 
ds.Tables("tblPayment").Rows.Add(strSupplierRecord)
 
Next
 
End Sub
 
Private Sub S_CreateTable(ByVal ds As DataSet)
Dim tblDS As DataTable = New DataTable("tblPayment")
tblDS.Columns.Add("Supplier_Code", Type.GetType("System.Int32"))
tblDS.Columns.Add("Supllier_Name", Type.GetType("System.String"))
tblDS.Columns.Add("Period", Type.GetType("System.Int32"))
tblDS.Columns.Add("Sales_Of_Event", Type.GetType("System.Int32"))
tblDS.Columns.Add("Haigac_Of_Event", Type.GetType("System.Int32"))
tblDS.Columns.Add("Event_Rate", Type.GetType("System.Int32"))
tblDS.Columns.Add("Consumption_Tax", Type.GetType("System.Int32"))
tblDS.Columns.Add("Amount_Of_Money_Payment", Type.GetType("System.Int32"))
ds.Tables.Add(tblDS)
End Sub
 
Last edited by a moderator:
Back
Top