Solved

Datatable - Appending Rows

Posted on 2006-11-06
4
384 Views
Last Modified: 2010-04-23

Hi there, how would you add a row to a datatable?

I have a look up table with id and description columns.  On loading into VB I want to load data to a combo box, however I want to add another few rows only specific to certain screens in the app.

Thanks!!
0
Comment
Question by:DavidGreenfield
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:ChadMarsh
ID: 17881867
Hi David,
Just wanting to clairify you question. Do you want these rows to exist in the database, the datatable, or just the combo box?
Chad
0
 

Author Comment

by:DavidGreenfield
ID: 17882007
just the combo box thanks, but I am setting the datasource to be a table from a database!  The data I want to add are just options for a given form where I do some processing based on the selection.  Only relevant in the particular form loaded and as other systems are using the same look up tables I didn't want to start putting data specific to my app into the database.
0
 
LVL 2

Accepted Solution

by:
ChadMarsh earned 450 total points
ID: 17882352
Since you are binding to a datasoure, I would do it this way.
Dim t as DataTable = your datasource
with t
  Dim r as DataRow
   r= t.NewRow
   r("id") = your new id
   r("description") = your description
  .Rows.Add(r)
End With
combobox.datasource = t
combobox.DisplayMember = "description"
combobox.ValueMember = "id"

Hope this helps
Chad
0
 
LVL 3

Assisted Solution

by:vsvb
vsvb earned 50 total points
ID: 17884482
This is suppose your code for connect your database

Function DatasetGetDB() as dataset

        Dim loConnection As SqlConnection
        Dim constr As String = "Data Source=XXX;Initial Catalog=Testing;Integrated Security=SSPI;"
        loConnection = New SqlConnection(constr) '"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=(Datasqldev);Connect    Timeout=30")
        loConnection.Open()

        Dim loCommand As SqlCommand
        Dim loResult As New DataSet
        Dim loAdapter As SqlDataAdapter
        loCommand = New SqlCommand("select * from mytablename", loConnection)
        loCommand.CommandType = CommandType.Text
        loAdapter = New SqlDataAdapter(loCommand)
        loAdapter.Fill(loResult, "tablename")
        DatasetGetDB= loResult

End Funciton

Now you are getting this dataset with DatasetGetDB.table("mytablename")
But now you want some more row okay
the code is like this

Dim dtrow as datarow
dtrow = DatasetGetDB.table("mytablename").NewRow
With dtrow
    .item(0) ="lækæl"
....
...
...
End with
DatasetGetDB.table("mytablename").Addnew
DatasetGetDB.table("mytablename").Rows.Add(dtrow)

now you use this ...DatasetGetDB.table("mytablename") with added row
-













0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question