PC Review


Reply
Thread Tools Rate Thread

Adding a second table to this DataSet.

 
 
Manuel Canas
Guest
Posts: n/a
 
      12th Jul 2004
Hey guys,

This code was posted by Cor Ligther some rows below here. hey bud if you
read this one can you help me out here or anybody that know the answer to
this one.

How would I add a second table to this DataSet?

Thanks Guys.

Private Sub FillDatasetAndBindings()
ds.Clear()
Dim sqlString As String = "Select * from countries"
da = New OleDb.OleDbDataAdapter(sqlString, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)
dv = New DataView(dt)
dv.Sort = "Id"
cma = DirectCast(BindingContext(dv), CurrencyManager)
Dim cmb As New OleDb.OleDbCommandBuilder(da)
TextBox1.DataBindings.Clear()
TextBox2.DataBindings.Clear()
TextBox1.DataBindings.Add("text", dv, "Id")
TextBox2.DataBindings.Add("text", dv, "Name")
ListBox1.DataSource = dv
ListBox1.DisplayMember = "Name"
If ds.Tables(0).Rows.Count = 0 Then
cma.AddNew()
TextBox1.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Adding of a new row
cma.AddNew()
TextBox1.Focus()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'Delete
dv(cma.Position).Delete()
End Sub
Private Sub Button3_Click_1(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
'Add it to the dataset and to the
cma.EndCurrentEdit()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'Write it to the database
cma.EndCurrentEdit()
If ds.HasChanges Then
Try
da.Update(ds)
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
End If
End Sub
////

Manuel


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      12th Jul 2004
Hi,

Here is a sample that adds 3 tables to a dataset and sets up
relations between them.

http://www.onteorasoftware.com/downloads/multigrids.zip

Ken
---------------------------
"Manuel Canas" <(E-Mail Removed)> wrote in message
news:gznIc.22664$2i3.20434@clgrps12...
> Hey guys,
>
> This code was posted by Cor Ligther some rows below here. hey bud if you
> read this one can you help me out here or anybody that know the answer to
> this one.
>
> How would I add a second table to this DataSet?
>
> Thanks Guys.
>
> Private Sub FillDatasetAndBindings()
> ds.Clear()
> Dim sqlString As String = "Select * from countries"
> da = New OleDb.OleDbDataAdapter(sqlString, conn)
> da.Fill(ds)
> Dim dt As DataTable = ds.Tables(0)
> dv = New DataView(dt)
> dv.Sort = "Id"
> cma = DirectCast(BindingContext(dv), CurrencyManager)
> Dim cmb As New OleDb.OleDbCommandBuilder(da)
> TextBox1.DataBindings.Clear()
> TextBox2.DataBindings.Clear()
> TextBox1.DataBindings.Add("text", dv, "Id")
> TextBox2.DataBindings.Add("text", dv, "Name")
> ListBox1.DataSource = dv
> ListBox1.DisplayMember = "Name"
> If ds.Tables(0).Rows.Count = 0 Then
> cma.AddNew()
> TextBox1.Focus()
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button1.Click
> 'Adding of a new row
> cma.AddNew()
> TextBox1.Focus()
> End Sub
> Private Sub Button2_Click(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button2.Click
> 'Delete
> dv(cma.Position).Delete()
> End Sub
> Private Sub Button3_Click_1(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button3.Click
> 'Add it to the dataset and to the
> cma.EndCurrentEdit()
> End Sub
> Private Sub Button4_Click(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button4.Click
> 'Write it to the database
> cma.EndCurrentEdit()
> If ds.HasChanges Then
> Try
> da.Update(ds)
> Catch ex As OleDb.OleDbException
> MessageBox.Show(ex.Message, "OleDbException")
> Exit Sub
> Catch ex As Exception
> MessageBox.Show(ex.Message, "GeneralException")
> Exit Sub
> End Try
> End If
> End Sub
> ////
>
> Manuel
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding table to DataSet Jeff Microsoft ADO .NET 1 11th Jul 2007 07:23 AM
Please help adding columns to the existing Dataset table settyv@gmail.com Microsoft ASP .NET 0 13th Nov 2006 04:30 PM
problems adding a second table to a dataset TB Microsoft ASP .NET 4 25th Jan 2006 04:10 PM
adding a table (view) to a dataset =?Utf-8?B?YW1iZXI=?= Microsoft Dot NET 0 2nd Dec 2005 07:39 PM
Error Message - Adding Table to Dataset =?Utf-8?B?TWFyaw==?= Microsoft VB .NET 6 4th Nov 2005 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:23 AM.