datatable and dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like to create a datatable and add rows to it, but not make it part of a
dataset. so far i've not seen too many examples of this. I believe it can be
done. does anyone know of an example?
thanks
kes
 
here is a simple example in VB:

Dim dt As New DataTable
Dim dr As DataRow

dt.Columns.Add("MyNewColumn")

For i As Integer = 1 to 5
dr = dt.NewRow()
dr("MyNewColumn") = "value" & i
dt.Rows.Add(dr)
Next
 
kes,
Here is an example that I just posted in response to another question:

Dim table As New DataTable("RJN")
table.Columns.Add("InstanceId", GetType(Integer))
table.Columns.Add("LevelId", GetType(Integer))
table.Columns.Add("ParentId", GetType(Integer))

table.Rows.Add(New Object() {100, 1, Nothing})
table.Rows.Add(New Object() {101, 2, 100})
table.Rows.Add(New Object() {102, 3, 101})
table.Rows.Add(New Object() {103, 4, 102})
table.Rows.Add(New Object() {104, 5, 103})
table.Rows.Add(New Object() {105, 5, 104})
table.Rows.Add(New Object() {106, 5, 104})


The "problem" currently is that DataTable in .NET 1.0 & 1.1 (VS.NET 2002 &
2003) do not support the ReadXml & WriteXml methods. I understand that .NET
2.0 (VS.NET 2005) will add support for these methods ot DataTable.

Hope this helps
Jay

| I'd like to create a datatable and add rows to it, but not make it part of
a
| dataset. so far i've not seen too many examples of this. I believe it can
be
| done. does anyone know of an example?
| thanks
| kes
| --
| thanks (as always)
| some day i''m gona pay this forum back for all the help i''m getting
| kes
 
thanks
related question: i'm trying to bind this to a dropdown list
i'm trying
Me.ddlMemType.DataSource = table.TableName
Me.ddlMemType.DataTextField = ....
this does not work. how would i do this?
thnaks
kes
 
just change it to Me.ddlMemType.DataSource= table
Me.ddlMemType.DataTextField = "FieldName"
 
Kes,
As W.G. Ryan states:

Bind only the DataTable itself to the DataSource.

| Me.ddlMemType.DataSource = table
| Me.ddlMemType.DataTextField = ....

By setting the DataSource = table.TableName you were attempting to bind to a
String...

Hope this helps
Jay

| thanks
| related question: i'm trying to bind this to a dropdown list
| i'm trying
| Me.ddlMemType.DataSource = table.TableName
| Me.ddlMemType.DataTextField = ....
| this does not work. how would i do this?
| thnaks
| kes
| --
| thanks (as always)
| some day i''m gona pay this forum back for all the help i''m getting
| kes
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > kes,
| > Here is an example that I just posted in response to another question:
| >
| > Dim table As New DataTable("RJN")
| > table.Columns.Add("InstanceId", GetType(Integer))
| > table.Columns.Add("LevelId", GetType(Integer))
| > table.Columns.Add("ParentId", GetType(Integer))
| >
| > table.Rows.Add(New Object() {100, 1, Nothing})
| > table.Rows.Add(New Object() {101, 2, 100})
| > table.Rows.Add(New Object() {102, 3, 101})
| > table.Rows.Add(New Object() {103, 4, 102})
| > table.Rows.Add(New Object() {104, 5, 103})
| > table.Rows.Add(New Object() {105, 5, 104})
| > table.Rows.Add(New Object() {106, 5, 104})
| >
| >
| > The "problem" currently is that DataTable in .NET 1.0 & 1.1 (VS.NET 2002
&
| > 2003) do not support the ReadXml & WriteXml methods. I understand that
..NET
| > 2.0 (VS.NET 2005) will add support for these methods ot DataTable.
| >
| > Hope this helps
| > Jay
| >
message
| > | > | I'd like to create a datatable and add rows to it, but not make it
part of
| > a
| > | dataset. so far i've not seen too many examples of this. I believe it
can
| > be
| > | done. does anyone know of an example?
| > | thanks
| > | kes
| > | --
| > | thanks (as always)
| > | some day i''m gona pay this forum back for all the help i''m getting
| > | kes
| >
| >
| >
 
thank you both for replying
this works!!
it seems its the simple ones that cause me the most greif!!!
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top