Solved

Datatable - Appending Rows

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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