473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Creating A DataSet Programmatically

The following ASPX code snippet creates a DataSet programmatically right from the scratch:

'create an empty DataSet
Dim objDS As New DataSet("MyDataSet")

'create a new table & add columns
Dim dTable As New DataTable("Users")
dTable.Columns.Add("ID",System.Type.GetType("Syste m.Int32"))
dTable.Columns.Add("FirstName",System.Type.GetType ("System.String"))
dTable.Columns.Add("LastName",System.Type.GetType( "System.String"))
dTable.Columns("ID").AutoIncrement=True

'add the new table
objDS.Tables.Add(dTable)

'define the Primary Key
Dim keys As DataColumn={objDS.Tables("Users").Columns("ID")}
objDS.Tables("Users").PrimaryKey=keys

'add a row to this table
Dim dRow As DataRow=dTable.NewRow()
dRow(1)="Michael"
dRow(2)="Johnson"
dTable.Rows.Add(dRow)

As such, the above code doesn't generate any errors but how do I access this DataSet i.e. how do I convert it into an actual file or insert it in a database so that I can access the data that it stores (presently it stores only one row - Michael as the FirstName & Johnson as the LastName)?

Thanks,

Arpan
Nov 19 '05 #1
1 16555
You can access this in a number of ways or even write it to
disk, that's actually quite a loaded question. If you had
done a little research you'd have quickly found answers to
this.

You can write a DataSet to disk and read it back into a
DataSet in memory whenever you like, you may also generate
schemas for the XML you generate, see here:

http://samples.gotdotnet.com/quickst...ataSetXML.aspx

As for reading into a database, there are a number of ways
to do this. A DataSet is a database represented in memory
and is composed of XML (to make a long story short).

It is comprised of DataTables, DataViews, DataRelations,
etc. You can use DataReaders to read data out of the
DataSet or you can use Commands to write data into your
database. You can even create relationships between
DataTables in memory and enforce integrity.

There's obviously much more, try these links for starters:

http://msdn.microsoft.com/library/de...xmldataset.asp

http://www.c-sharpcorner.com/databas...net.tut.sh.asp

http://www.411asp.net/home/tutorial/...lasses/dataset

-----Original Message-----
The following ASPX code snippet creates a DataSet programmatically right from the scratch:
'create an empty DataSet
Dim objDS As New DataSet("MyDataSet")

'create a new table & add columns
Dim dTable As New DataTable("Users")
dTable.Columns.Add("ID",System.Type.GetType("Syst em.Int32"))
dTable.Columns.Add("FirstName",System.Type.GetTyp e("System.String"))
dTable.Columns.Add("LastName",System.Type.GetType ("System.String"))
dTable.Columns("ID").AutoIncrement=True

'add the new table
objDS.Tables.Add(dTable)

'define the Primary Key
Dim keys As DataColumn={objDS.Tables("Users").Columns("ID")}
objDS.Tables("Users").PrimaryKey=keys

'add a row to this table
Dim dRow As DataRow=dTable.NewRow()
dRow(1)="Michael"
dRow(2)="Johnson"
dTable.Rows.Add(dRow)

As such, the above code doesn't generate any errors but how do I access this DataSet i.e. how do I convert it into
an actual file or insert it in a database so that I can
access the data that it stores (presently it stores only
one row - Michael as the FirstName & Johnson as the LastName)?
Thanks,

Arpan

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
15
by: ruca | last post by:
Hi, Can I read a .TXT File to a DataSet? How can I do that? I want to read his lines to a DropDownList. This lines are the names of employees that I export from an application that I have. I...
4
by: Grigs | last post by:
Hello, I have an asp:table on my page. I am, after a button gets clicked, programmatically adding rows and their cells. Using the Cell.Text = to put the value in the cell. I then have another...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
5
by: Peter Schoots | last post by:
I am an amateur programmer and trying to move from VB6 to VB.net. I can't figure out how to create a ADO.NET database in code. I know how to create a dataset and wonder whether there is a way to...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
3
by: Priya | last post by:
Hi, I need to create a temp table in my asp.net web services program. I have an xml file of the format <uom_masters> <uom_code>varchar</uom_code> <uom_description>varchar</uom_description>...
4
by: nautiboy | last post by:
This seems like it should be so trivial, but try as I might I can't figure it out. I want to write out a dataset as xml (i.e., DataSet.WriteXml()) but use the tablename as the root element instead...
8
by: Andrzej Lipski | last post by:
I am new to dotnet and I'll tried searching Google for a solution to my problem. I am hoping that it is possible to do, or am I going down a dead end? I have a User class that has known...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.