Solved

Datatable - Appending Rows

Posted on 2006-11-06
4
368 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now