Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Datatable - Appending Rows

Posted on 2006-11-06
4
Medium Priority
?
391 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 1800 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

926 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