473,396 Members | 1,814 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.

pb with adding columns to a datatable

Sam
Hi,
I'm adding columns to a datatable as followed. The values are from
textboxes or comboboxes.
The first column is properly field but then all the subsequent columns
just contain "", whereas the source txtboxes or comboboxes values are
correct. Why is that ?

thx

Dim dt As New DataTable
Dim row As DataRow

dt.Columns.Add("FieldName", Type.GetType("System.String"))
row = dt.NewRow
row("FieldName") = txtFieldName.Text
dt.Rows.Add(row) --> contains "the right string"

dt.Columns.Add("EntryInfo", Type.GetType("System.String"))
row = dt.NewRow
row("EntryInfo") = txtEntryInfo.Text
dt.Rows.Add(row) --> contains "" instead of "a string"

Nov 21 '05 #1
4 1537
First of all - pb is the chemical symbol for lead and this is not an SMS
newsgroup so there is no need to abbreviate things.

The code you have shown will give you a table that looks like this:

FieldName EntryInfo Whatever
--------- --------- --------
Row 0 aaa
Row 1 bbb
Row 2 ccc

I assume that this is probably not what you want.

If, instead, you want this:

FieldName EntryInfo Whatever
--------- --------- --------
Row 0 aaa bbb ccc

then you need:

Dim dt As New DataTable
Dim row As DataRow
dt.Columns.Add("FieldName", Type.GetType("System.String"))
dt.Columns.Add("EntryInfo", Type.GetType("System.String"))
dt.Columns.Add("Whatever", Type.GetType("System.String"))
row = dt.NewRow
row("FieldName") = txtFieldName.Text
row("EntryInfo") = txtEntryInfo.Text
row("Whatever") = txtWhatever.Text
dt.Rows.Add(row)
"Sam" <sa**************@voila.fr> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi,
I'm adding columns to a datatable as followed. The values are from
textboxes or comboboxes.
The first column is properly field but then all the subsequent columns
just contain "", whereas the source txtboxes or comboboxes values are
correct. Why is that ?

thx

Dim dt As New DataTable
Dim row As DataRow

dt.Columns.Add("FieldName", Type.GetType("System.String"))
row = dt.NewRow
row("FieldName") = txtFieldName.Text
dt.Rows.Add(row) --> contains "the right string"

dt.Columns.Add("EntryInfo", Type.GetType("System.String"))
row = dt.NewRow
row("EntryInfo") = txtEntryInfo.Text
dt.Rows.Add(row) --> contains "" instead of "a string"

Nov 21 '05 #2
Sam
Hehe... sorry for the sms style. And my error was stupid. Thanks a lot.

Nov 21 '05 #3
Sam,

I would change it in this typed in this message so watch typos..

\\\
Dim dt As New DataTable
dt.Columns.Add("FieldName", GetType(System.String))
dt.Columns.Add("EntryInfo", GetType(System.String))
dt.loaddatarow(new Object() {txtFieldName.Text,txtEntryInfo.Text},true)
///

A lot shorter and the rowstate is direct set to unchanged in this case
(otherwise false).

Cor
Nov 21 '05 #4
Sam
Thx Cor, looks good

Nov 21 '05 #5

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

Similar topics

1
by: VMI | last post by:
In my Win app, I call a method that returns a datatable with all its columns and is filled with data. After the table's returned, I need to add another column to the datatable that will include...
6
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
10
by: Bernie Yaeger | last post by:
I have a need to add a primary key to a dataset/datatable. How can this be done using a standard oledb data provider? Tx for any help.
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
6
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.