473,406 Members | 2,217 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,406 software developers and data experts.

InMemory DataSet

I want to create an In Memory dataset. not connected to any database.. but
putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian
Aug 2 '08 #1
12 1412
On Aug 2, 6:43*pm, "Brian" <bsgalla...@community.nospamwrote:
I want to create an In Memory dataset. *not connected to any database..but
putting my own info in from code or a file....
What are the steps to do this? *Where can I find some info on how to do
this?
* * * Brian
Dim dataSet As New DataSet()

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Aug 2 '08 #2
All DataSets are in-memory and disconnected from any data source.

You should simply Google on .NET DataSet and read the many usefull articles
about them.

-Scott

"Brian" <bs********@community.nospamwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
>I want to create an In Memory dataset. not connected to any database.. but
putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian

Aug 3 '08 #3
lol...
ok.. a little more info...
I want to create a table with a few columns... and a few rows....

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ca**********************************@c65g2000 hsa.googlegroups.com...
On Aug 2, 6:43 pm, "Brian" <bsgalla...@community.nospamwrote:
I want to create an In Memory dataset. not connected to any database.. but
putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian
Dim dataSet As New DataSet()

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Aug 3 '08 #4
Brian wrote:
>
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ca**********************************@c65g2000 hsa.googlegroups.com...
On Aug 2, 6:43 pm, "Brian" <bsgalla...@community.nospamwrote:
>I want to create an In Memory dataset. not connected to any
database..

Dim dataSet As New DataSet()

lol...
ok.. a little more info...
I want to create a table with a few columns... and a few rows....
Same principle applies:
Dim DS As New DataSet("MyDataSet")
Dim DT As New DataTable("MyTable")
DT.Columns.Add("Test", GetType(String))
Dim DR As DataRow = DT.NewRow
DR.Item("Test") = "Hello, World"
DT.Rows.Add(DR)
DS.Tables.Add(DT)
DS.AcceptChanges()
' all done



Aug 3 '08 #5
ok... how do i make bind that with a dataview?...
here are the crazy things I've been trying
Public Class Form1

Private MyDS As DataSet = New DataSet

Private MyTable As DataTable = MyDS.Tables.Add("tblHolidays") 'New
DataTable("tblHolidays")

Private Sub testme()

'Dim dt As New DataTable("tblHolidays")

Dim dcfirstcolumn As New DataColumn("first")

Dim dcsecondcolumn As New DataColumn("second")

dcfirstcolumn.DataType = System.Type.GetType("System.DateTime")

dcsecondcolumn.DataType = System.Type.GetType("System.String")

MyTable.Columns.Add(dcfirstcolumn)

MyTable.Columns.Add(dcsecondcolumn)

Dim dr As DataRow = MyTable.NewRow() '= dt.Rows.Add ' 'dt.rows.newrow

MyTable.Rows.Add(dr)

dr.Item(dcfirstcolumn) = #1/1/2008#

dr.Item(dcsecondcolumn) = "New Years"

dr.AcceptChanges()

'MyTable.Rows(1).Item(0) = #1/1/2009#

' dr.

Me.DataGridView1.DataSource = Me.MyDS.Tables

MyDS.AcceptChanges()

'Me.DataGridView1.DataBindings

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'With MyDS

' With MyTable

' .Columns.Add("dtmHoliday", Type.GetType("System.DateTime"))

' .Columns.Add("strHoliday", Type.GetType("System.String"))

' .Columns(1).ColumnName = "test"

' .Columns(0).Caption = "test caption"

' End With

' Console.WriteLine("Rows: {0}", .Tables(0).Rows.Count)

' MyTable.Rows.Add()

' Dim strSQL As String = "INSERT INTO tblHolidays (dtmHoliday, strHoliday)
values (#1/1/2009#, 'Testme')"

' Dim selectCMD As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL)

' 'selectCMD.ExecuteScalar()

' Console.WriteLine("Rows: {0}", .Tables(0).Rows.Count)

' .AcceptChanges()

Dim DS As New DataSet("MyDataSet")

Dim DT As New DataTable("MyTable")

DT.Columns.Add("Test", GetType(String))

Dim DR As DataRow = DT.NewRow

DR.Item("Test") = "Hello, World"

DT.Rows.Add(DR)

DS.Tables.Add(DT)

DS.AcceptChanges()

Me.DataGridView1.DataSource = DS.Tables

'End With

'testme()

End Sub

End Class



"Steve Gerrard" <my********@comcast.netwrote in message
news:NP******************************@comcast.com. ..
Brian wrote:
>>
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ca**********************************@c65g200 0hsa.googlegroups.com...
On Aug 2, 6:43 pm, "Brian" <bsgalla...@community.nospamwrote:
>>I want to create an In Memory dataset. not connected to any
database..

Dim dataSet As New DataSet()

lol...
ok.. a little more info...
I want to create a table with a few columns... and a few rows....

Same principle applies:
Dim DS As New DataSet("MyDataSet")
Dim DT As New DataTable("MyTable")
DT.Columns.Add("Test", GetType(String))
Dim DR As DataRow = DT.NewRow
DR.Item("Test") = "Hello, World"
DT.Rows.Add(DR)
DS.Tables.Add(DT)
DS.AcceptChanges()
' all done



Aug 3 '08 #6
Brian wrote:
ok... how do i make bind that with a dataview?...
here are the crazy things I've been trying

Me.DataGridView1.DataSource = DS.Tables
And the problem is what? :)

You may just need to try one of these two:
Me.DataGridView1.DataSource = DS.Tables("MyTable")
or
Me.DataGridView1.DataSource = DS
Me.DataGridView1.DataMember = "MyTable"

Aug 3 '08 #7
Brian,

You use the code to set the datasource of a datagrid, that can be a dataset.

A dataGridView only accept one table. Probably the DataGrid was to complex
and therefore Microsoft has introduced an in fact more simple "Data" grid.

By the way, be aware that the "acceptchanges" is not really needed in the
sample from Steve.
It can be done, does not harm, but that depends if you want to keep the
adding of the start row as new row ar as begin row.

I also would not use the literal dates. It is from the time that Microsoft
was probably thinking that they were a local player on the markt and
therefore only really suitable in the USA.

After a lot of discussions in past in this newsgroup, we came with this as
the best solution to initiate a date.

dim mydate as datetime = new datetime(2008, 1, 1)
giving as result in every place on earth the first day of january of the
year 2008.

Cor
"Brian" <bs********@community.nospamschreef in bericht
news:OR**************@TK2MSFTNGP02.phx.gbl...
ok... how do i make bind that with a dataview?...
here are the crazy things I've been trying
Public Class Form1

Private MyDS As DataSet = New DataSet

Private MyTable As DataTable = MyDS.Tables.Add("tblHolidays") 'New
DataTable("tblHolidays")

Private Sub testme()

'Dim dt As New DataTable("tblHolidays")

Dim dcfirstcolumn As New DataColumn("first")

Dim dcsecondcolumn As New DataColumn("second")

dcfirstcolumn.DataType = System.Type.GetType("System.DateTime")

dcsecondcolumn.DataType = System.Type.GetType("System.String")

MyTable.Columns.Add(dcfirstcolumn)

MyTable.Columns.Add(dcsecondcolumn)

Dim dr As DataRow = MyTable.NewRow() '= dt.Rows.Add ' 'dt.rows.newrow

MyTable.Rows.Add(dr)

dr.Item(dcfirstcolumn) = #1/1/2008#

dr.Item(dcsecondcolumn) = "New Years"

dr.AcceptChanges()

'MyTable.Rows(1).Item(0) = #1/1/2009#

' dr.

Me.DataGridView1.DataSource = Me.MyDS.Tables

MyDS.AcceptChanges()

'Me.DataGridView1.DataBindings

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'With MyDS

' With MyTable

' .Columns.Add("dtmHoliday", Type.GetType("System.DateTime"))

' .Columns.Add("strHoliday", Type.GetType("System.String"))

' .Columns(1).ColumnName = "test"

' .Columns(0).Caption = "test caption"

' End With

' Console.WriteLine("Rows: {0}", .Tables(0).Rows.Count)

' MyTable.Rows.Add()

' Dim strSQL As String = "INSERT INTO tblHolidays (dtmHoliday, strHoliday)
values (#1/1/2009#, 'Testme')"

' Dim selectCMD As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL)

' 'selectCMD.ExecuteScalar()

' Console.WriteLine("Rows: {0}", .Tables(0).Rows.Count)

' .AcceptChanges()

Dim DS As New DataSet("MyDataSet")

Dim DT As New DataTable("MyTable")

DT.Columns.Add("Test", GetType(String))

Dim DR As DataRow = DT.NewRow

DR.Item("Test") = "Hello, World"

DT.Rows.Add(DR)

DS.Tables.Add(DT)

DS.AcceptChanges()

Me.DataGridView1.DataSource = DS.Tables

'End With

'testme()

End Sub

End Class



"Steve Gerrard" <my********@comcast.netwrote in message
news:NP******************************@comcast.com. ..
>Brian wrote:
>>>
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ca**********************************@c65g20 00hsa.googlegroups.com...
On Aug 2, 6:43 pm, "Brian" <bsgalla...@community.nospamwrote:
I want to create an In Memory dataset. not connected to any
database..

Dim dataSet As New DataSet()

lol...
ok.. a little more info...
I want to create a table with a few columns... and a few rows....

Same principle applies:
Dim DS As New DataSet("MyDataSet")
Dim DT As New DataTable("MyTable")
DT.Columns.Add("Test", GetType(String))
Dim DR As DataRow = DT.NewRow
DR.Item("Test") = "Hello, World"
DT.Rows.Add(DR)
DS.Tables.Add(DT)
DS.AcceptChanges()
' all done



Aug 3 '08 #8
There is another middle ground approach.

Create a strongl (-ly typed) dataset. And do it in memory.

Here is a crappy example I just wrote up for another person.

Sorry for the c# syntax, it'll convert easy.
Create a new strongly typed DataSet. Call it "StateStuffDS" (or whatever
you want to call it, try to avoid ambiguity)

Add 3 tables (with the columns)

State
StateID (int)
StateName (string)
StateAbbreviation (string)

StateRule
StateRuleID (int)
StateRuleText (string)
StateToStateRule
StateID (int)
StateRuleID (int)


Here is some psedu code.
StateStuffDS ds = new StateStuffDS();

ds.State.AddNewStateRow( 101, "Virginia", "VA");
ds.StateRule.AddNewStateRule ( 1001, "Is For Lovers" );
ds.StateToStateRule.AddStateToStateRule( 101, 1001);

ds.WriteXml (@"C:\myds.xml");
.........................

StateStuffDS anotherDS = new StateStuffDS();
anotherDS.Read("C:\myds.xml");
DataRow [] foundRows = ds.State.Select("StateAbbreviation = 'VA'");
//include the System.Data namespace

if(foundRows.Length 0) //or is it .Count?
{
StateStuffDS.State.StateRow currentRow = foundRows[0] as
StateStuffDS.State.StateRow; //just a test to pop off the first row
if(null!= currentRow)
{
Console.Writeline (currentRow.StateName);
}
}

You get some strong typing this way, even in the DataSet model.


Good luck!


"Brian" <bs********@community.nospamwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
>I want to create an In Memory dataset. not connected to any database.. but
putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian

Aug 4 '08 #9
sloan,

A strongly typed dataset is normally inheriting the dataset class, I miss
that in your code.

Any idea what I miss?

Cor

"sloan" <sl***@ipass.netschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
There is another middle ground approach.

Create a strongl (-ly typed) dataset. And do it in memory.

Here is a crappy example I just wrote up for another person.

Sorry for the c# syntax, it'll convert easy.
Create a new strongly typed DataSet. Call it "StateStuffDS" (or whatever
you want to call it, try to avoid ambiguity)

Add 3 tables (with the columns)

State
StateID (int)
StateName (string)
StateAbbreviation (string)

StateRule
StateRuleID (int)
StateRuleText (string)
StateToStateRule
StateID (int)
StateRuleID (int)


Here is some psedu code.
StateStuffDS ds = new StateStuffDS();

ds.State.AddNewStateRow( 101, "Virginia", "VA");
ds.StateRule.AddNewStateRule ( 1001, "Is For Lovers" );
ds.StateToStateRule.AddStateToStateRule( 101, 1001);

ds.WriteXml (@"C:\myds.xml");
........................

StateStuffDS anotherDS = new StateStuffDS();
anotherDS.Read("C:\myds.xml");
DataRow [] foundRows = ds.State.Select("StateAbbreviation = 'VA'");
//include the System.Data namespace

if(foundRows.Length 0) //or is it .Count?
{
StateStuffDS.State.StateRow currentRow = foundRows[0] as
StateStuffDS.State.StateRow; //just a test to pop off the first row
if(null!= currentRow)
{
Console.Writeline (currentRow.StateName);
}
}

You get some strong typing this way, even in the DataSet model.


Good luck!


"Brian" <bs********@community.nospamwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
>>I want to create an In Memory dataset. not connected to any database..
but putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian

Aug 4 '08 #10

I think my syntax was el-crappo.

Here is some rewording:
Create a strongl (-ly typed) dataset (through the IDE)
<<strike out>>And do it in memory.<</strike out>>
<<new sentence>>And then you will have the ability to create your dataset in
memory, but at the same time, you'll have access to "strong" typing,
intellisense, etc.
<</new sentence>>
.............

When you go through the IDE and "add new item/ dataset", you are basically
creating a object that will inherit from DataSet.
However, all your tables and columns will be "pre-defined", thus you won't
have to write code like this:

Dim DS As New DataSet("MyDataSet")
Dim DT As New DataTable("MyTable")
DT.Columns.Add("Test", GetType(String))
......
I am NOT saying there is never a time to write code like that. I'm saying
there is another option.
If you're entities are fairly stable, then I prefer the strong dataset
approach over a loose dataset approach.



"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:55**********************************@microsof t.com...
sloan,

A strongly typed dataset is normally inheriting the dataset class, I miss
that in your code.

Any idea what I miss?

Cor

"sloan" <sl***@ipass.netschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>There is another middle ground approach.

Create a strongl (-ly typed) dataset. And do it in memory.

Here is a crappy example I just wrote up for another person.

Sorry for the c# syntax, it'll convert easy.
Create a new strongly typed DataSet. Call it "StateStuffDS" (or
whatever
you want to call it, try to avoid ambiguity)

Add 3 tables (with the columns)

State
StateID (int)
StateName (string)
StateAbbreviation (string)

StateRule
StateRuleID (int)
StateRuleText (string)
StateToStateRule
StateID (int)
StateRuleID (int)


Here is some psedu code.
StateStuffDS ds = new StateStuffDS();

ds.State.AddNewStateRow( 101, "Virginia", "VA");
ds.StateRule.AddNewStateRule ( 1001, "Is For Lovers" );
ds.StateToStateRule.AddStateToStateRule( 101, 1001);

ds.WriteXml (@"C:\myds.xml");
........................

StateStuffDS anotherDS = new StateStuffDS();
anotherDS.Read("C:\myds.xml");
DataRow [] foundRows = ds.State.Select("StateAbbreviation = 'VA'");
//include the System.Data namespace

if(foundRows.Length 0) //or is it .Count?
{
StateStuffDS.State.StateRow currentRow = foundRows[0] as
StateStuffDS.State.StateRow; //just a test to pop off the first row
if(null!= currentRow)
{
Console.Writeline (currentRow.StateName);
}
}

You get some strong typing this way, even in the DataSet model.


Good luck!


"Brian" <bs********@community.nospamwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
>>>I want to create an In Memory dataset. not connected to any database..
but putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian


Aug 5 '08 #11
.....
I am NOT saying there is never a time to write code like that. I'm saying
there is another option.
If you're entities are fairly stable, then I prefer the strong dataset
approach over a loose dataset approach.
me too.

:-)

Cor

Aug 7 '08 #12
silly me.. found what I was doing wrong.... had bound to a blank table
through the gui.....

"Scott M." <s-***@nospam.nospamwrote in message
news:eP**************@TK2MSFTNGP05.phx.gbl...
All DataSets are in-memory and disconnected from any data source.

You should simply Google on .NET DataSet and read the many usefull
articles about them.

-Scott

"Brian" <bs********@community.nospamwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
>>I want to create an In Memory dataset. not connected to any database..
but putting my own info in from code or a file....
What are the steps to do this? Where can I find some info on how to do
this?
Brian


Aug 9 '08 #13

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

Similar topics

3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
1
by: Andy | last post by:
Hello, I have a WebService that sends a client a DataSet as XML (I use a DataSet.GetXml to get the XML). The DataSet is filled by a DataAdapter in the WebService. The client coverts the XML Back...
5
by: Mike | last post by:
I need to expand the DataSet class by inheriting from it and adding functions that work on the data in the tables. However, since I can't upcast how can I get my base DataSet object assigned an...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
2
by: Jan | last post by:
Regarding my post "CSharpCodeProvider: referencing other generated "InMemory" assembly" 4/27/2006 and the blog from Greg Young http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx I...
2
by: Wolfgang Hauer | last post by:
Hallo! Ich habe eine inmemory-bitmap. die ich leider in eine png-datei umwandeln muss. ich mache das jetzzt so: b = New...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
3
by: Martin Z | last post by:
Hi, I have an application that involves sending a lot of XML data to various places. The problem is that once in a while, I just want the XML document as a string (for example, sending to a...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.