Showing posts with label DataSet. Show all posts
Showing posts with label DataSet. Show all posts

2007-11-08

Copying Data from one DataTable to Another

You can use ImportRow method to do this by calling NewRow adds a row to the table using the existing table schema, but with default values for the row, and sets the DataRowState to Added. Calling ImportRow preserves the existing DataRowState along with other values in the row. If the DataRow that is passed as a parameter is in a detached state, it is ignored, and no exception is thrown.

Sample Code

For Each dr As DataRow In sourceTable.Rows

destinationTable.ImportRow(dr)

Next

But if the destination table have the same structure you can use this clone method copies the structure of the DataSet that including all datatable schemas, relations, and constraints.

Sample Code

Dim dsDestination As DataSet
' clone method copies the structure of the DataSet,
' including all datatable schemas, relations, and constraints
dsDestination = ds.Clone()

For Each dr As DataRow In ds.Tables(0).Rows
dsDestination.Tables(0).ImportRow(dr)
Next

vb.net sample code

2007-11-02

DataSet

A data set (or dataset) is a collection of data, usually presented in tabular form. Each column represents a particular variable. Each row corresponds to a given member of the data set in question. It lists values for each of the variables, such as height and weight of an object or values of random numbers. The data set may comprise data for one or more members, corresponding to the number of rows.

Historically, the term originated in the mainframe field, where it had a well-defined meaning, very close to contemporary computer file. This topic is not covered here.

In the simplest case, there is only one variable, and then the data set consists of a single column of values, often represented as a list.

The values may be numbers, such as real numbers or integers, for example representing a person's height in centimeters, but may also be nominal data (i.e., not consisting of numerical values), for example representing a person's ethnicity. For each variable, the values will normally all be of the same kind. However, there may also be "missing values", which need to be indicated in some way.

In statistics data sets usually come from actual observations obtained by sampling a statistical population, and each row corresponds to the observations on one element of that population. Data sets may further be generated by algorithms for the purpose of testing certain kinds of software.

While the term suggests a relationship to set theory it should not be assumed that a given data set is, in fact, a set in the usual mathematically sense. The rows of a data set need not be distinct, and so a data set is technically a multiset.

From Wikipedia, the free encyclopedia

2007-08-03

Gets Array of all DataRow

After you create or bind data into DataSet and you need select some data from them. You can use select method in datable.

DataTable.Select Method (String) Gets an array of all DataRow objects that match the filter criteria in order of primary key (or lacking one, order of addition.)

Sample 1. You can copy code from Step to Create Dataset topic and try to run this sample.

Dim drSelect As DataRow() = ds.Tables(0).Select("Column1=3")
Dim sTemp As String = ""

If drSelect.Length > 0 Then
For Each drItem As DataRow In drSelect
sTemp = sTemp & drItem("Column2").ToString() & ","
Next

MessageBox.Show(sTemp.Substring(0, sTemp.Length - 1))
End If


Sample 2.

Private Sub GetRowsByFilter()
Dim t As DataTable
t = DataSet1.Tables("Orders")
' Presuming the DataTable has a column named Date.
Dim strExpr As String
strExpr = "Date > '1/1/00'"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = t.Select(strExpr)
Dim i As Integer
' Print column 0 of each returned row.
For i = 0 to foundRows.GetUpperBound(0)
Console.WriteLine(foundRows(i)(0))
Next i
End Sub

2007-07-12

Step to Create Dataset

This sample show the basic step to create dataset and there element.


Sample Code

Step 1 you should to Imports System.Data

Step 2 please see sample code below.

Dim ds As New DataSet("DataSetSample")

' Create Table
Dim dt As New DataTable("DataTable")

' Create Column
Dim cl1 As New DataColumn("Column1")
cl1.DataType = GetType(Integer)

Dim cl2 As New DataColumn("Column2")
cl2.DataType = GetType(String)

' Add column to table
dt.Columns.Add(cl1)
dt.Columns.Add(cl2)

' Add DataTable to DataSet
ds.Tables.Add(dt)

' Step to add DataRow
' Create new row
Dim dr As DataRow
dr = ds.Tables("DataTable").NewRow

dr("Column1") = 1
dr("Column2") = "Welcome to vb.net Sample code"

' Add Row1
ds.Tables("DataTable").Rows.Add(dr)


' If you can use array of datarow.
Dim drArray(1) As DataRow

drArray(0) = ds.Tables(0).NewRow
drArray(0)("Column1") = 2
drArray(0)("Column2") = "Show easy sample code"
ds.Tables("DataTable").Rows.Add(drArray(0))

drArray(1) = ds.Tables(0).NewRow
drArray(1)("Column1") = 3
drArray(1)("Column2") = "Easy to understand"
ds.Tables("DataTable").Rows.Add(drArray(1))


' binddata to gridview
Me.DataGridView1.DataSource = ds.Tables("DataTable").Copy()


vb.net sample code