Solved

Datatable - Appending Rows

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Showdialog 8 29
how to use laptop or pad camera in vb.net windows application 2 45
Advice in Xamarin 21 44
Need a starter for ETL protocol? 4 31
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

19 Experts available now in Live!

Get 1:1 Help Now