473,770 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("S ystem.String"))
row = dt.NewRow
row("FieldName" ) = txtFieldName.Te xt
dt.Rows.Add(row ) --> contains "the right string"

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

Nov 21 '05 #1
4 1553
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("S ystem.String"))
dt.Columns.Add( "EntryInfo" , Type.GetType("S ystem.String"))
dt.Columns.Add( "Whatever", Type.GetType("S ystem.String"))
row = dt.NewRow
row("FieldName" ) = txtFieldName.Te xt
row("EntryInfo" ) = txtEntryInfo.Te xt
row("Whatever") = txtWhatever.Tex t
dt.Rows.Add(row )
"Sam" <sa************ **@voila.fr> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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("S ystem.String"))
row = dt.NewRow
row("FieldName" ) = txtFieldName.Te xt
dt.Rows.Add(row ) --> contains "the right string"

dt.Columns.Add( "EntryInfo" , Type.GetType("S ystem.String"))
row = dt.NewRow
row("EntryInfo" ) = txtEntryInfo.Te xt
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.T ext,txtEntryInf o.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
2523
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 data from an ascii file. For example, the table may contain two columns: "emplcode" and "HrsWorked". Once I receive this table with all the data, I need to add another column to the datatable ("Name"), go through every row in the datatable and find...
6
3248
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 entry application. The code below gets line items from a SQL Server database and returns them to a datagrid by way of a DataTable called lineTable. As long as I am just displaying columns in the SQL database everything works well. I now want...
3
1955
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 example would be: Let's say Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and Column2, I need to do some calculations and display in as Column3. The calculations are easy and can be done in the code-behind. How to display...
1
3296
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 days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
10
2358
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 the DataAdd part (Section heading is Adding Rows to a DataSet) I dont really know what to do after i have added all the
10
27862
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
3567
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 DataTable("MyTable"); In the classes constructor, after InitializeComponent() I call the following
6
2354
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 so I can do this: myDataTable.Rows.Add(array()) instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")
2
3372
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(); private SQLiteConnection cn; private SQLiteDataAdapter adapterMacros; cn = new SQLiteConnection("Data Source = irDatabase.db3"); SQLiteCommand commandMacros = new SQLiteCommand(); commandMacros.CommandText = "SELECT * FROM irMacros"; adapterMacros =...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.