|
-
Nov 19th, 2003, 07:42 AM
#1
Thread Starter
Lively Member
dataset with multiple dataadapters
Here I'm again.
I'm constantly trying to code VB.NET, but it is pretty hard for a newby.
I was trying to write some code to create a dataset without using the wizard of VB.NET.
I wanted to create one dataset which is filled with two dataadapters (DAMainGroup and DAGroup), but it doesn't work.
My code is the following:
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
Dim dataset As dataset = New dataset
Dim connection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\softlist\softlist_database.mdb;")
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.ListBox2 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(24, 48)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(200, 69)
Me.ListBox1.TabIndex = 0
'
'ListBox2
'
Me.ListBox2.Location = New System.Drawing.Point(248, 48)
Me.ListBox2.Name = "ListBox2"
Me.ListBox2.Size = New System.Drawing.Size(200, 69)
Me.ListBox2.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(752, 365)
Me.Controls.Add(Me.ListBox2)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DAMainGroup As OleDbDataAdapter = New OleDbDataAdapter("select * from tblMainGroup", connection)
connection.Open()
DAMainGroup.Fill(dataset, "tblMainGroup")
connection.Close()
Me.ListBox1.DataSource = dataset.Tables("tblMainGroup")
Me.ListBox1.DisplayMember = "MaingroupDescription"
Me.ListBox1.ValueMember = "MaingroupID"
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim strSQLGroup As String
strSQLGroup = "SELECT GroupDescription FROM tblGroup where tblGroup.MainGroupID=" & Me.ListBox1.SelectedValue.ToString
Dim DAGroup As OleDbDataAdapter = New OleDbDataAdapter(strSQLGroup, connection)
DAGroup.Fill(dataset, "tblGroup")
Me.ListBox2.DataSource = dataset.Tables("tblGroup")
Me.ListBox2.DisplayMember = "GroupDescription"
End Sub
End Class
The error is at line 'DAGroup.Fill(dataset, "tblGroup")'. Is this because I want to fill the same dataset with two different dataadapters or has it something to do with the fact that the sqlstring for the DAGroup is based on what the user clicks in het first listbox?
Thanks,
Tom
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|