PC Review


Reply
Thread Tools Rate Thread

Where did my Dataset Go?

 
 
Wayne Wengert
Guest
Posts: n/a
 
      7th Jul 2004
I have a VB App (VSNET 2003) in which, during form load, I create a dataset
(ds1) and then populate a datagrid by binding to the dataset. That works
fine. The form has a button which, when clicked, initiates an export
process. When the button click event opens, the dataset is "Nothing". The
dataset is Dim'ed to be available throughout the form. Other variables
dim'ed at that same point are fine and can be used within the button click
event.

What is closing my dataset?

Wayne


 
Reply With Quote
 
 
 
 
Wayne Wengert
Guest
Posts: n/a
 
      7th Jul 2004
Sorry - It is a Windows app. Portion of code follows:

====================================
Public Class Form1

Inherits System.Windows.Forms.Form

Dim cn As SqlConnection

Dim strSelectedRegionalID = "Denver"

Dim strSQL As String

Dim ds1 As DataSet

Dim ShowSets As DataRelation

#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 DataGrid1 As System.Windows.Forms.DataGrid

Friend WithEvents btnXMLExport As System.Windows.Forms.Button

Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog

Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.DataGrid1 = New System.Windows.Forms.DataGrid

Me.btnXMLExport = New System.Windows.Forms.Button

Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog

Me.DataGrid2 = New System.Windows.Forms.DataGrid

CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()

CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'DataGrid1

'

Me.DataGrid1.DataMember = ""

Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText

Me.DataGrid1.Location = New System.Drawing.Point(12, 39)

Me.DataGrid1.Name = "DataGrid1"

Me.DataGrid1.Size = New System.Drawing.Size(472, 160)

Me.DataGrid1.TabIndex = 0

'

'btnXMLExport

'

Me.btnXMLExport.Location = New System.Drawing.Point(186, 429)

Me.btnXMLExport.Name = "btnXMLExport"

Me.btnXMLExport.Size = New System.Drawing.Size(104, 23)

Me.btnXMLExport.TabIndex = 1

Me.btnXMLExport.Text = "Export to XML"

'

'DataGrid2

'

Me.DataGrid2.DataMember = ""

Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText

Me.DataGrid2.Location = New System.Drawing.Point(12, 239)

Me.DataGrid2.Name = "DataGrid2"

Me.DataGrid2.Size = New System.Drawing.Size(472, 146)

Me.DataGrid2.TabIndex = 2

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(493, 457)

Me.Controls.Add(Me.DataGrid2)

Me.Controls.Add(Me.btnXMLExport)

Me.Controls.Add(Me.DataGrid1)

Me.Name = "Form1"

Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

Me.Text = "Form1"

CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()

CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Load the data

..........................

DataGrid1.DataSource = ds1

DataGrid1.DataMember = "CGShows" '<= ds1 is fine here

/'Wait for user to Click Button





Private Sub btnXMLExport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnXMLExport.Click



Dim filename As String = "myXmlDoc.xml".

Dim myFileStream As New System.IO.FileStream(filename,
System.IO.FileMode.Create)

ds1.WriteXml(myFileStream, XmlWriteMode.WriteSchema) ' <= ds1 is "Nothing
"here

End Sub

====================================
"BrianDH" <(E-Mail Removed)> wrote in message
news:13DBFF58-E5CD-4C08-84E7-(E-Mail Removed)...
> Web app or windows app?
>
> could we a code example?
>
> B
>
> "Wayne Wengert" wrote:
>
> > I have a VB App (VSNET 2003) in which, during form load, I create a

dataset
> > (ds1) and then populate a datagrid by binding to the dataset. That works
> > fine. The form has a button which, when clicked, initiates an export
> > process. When the button click event opens, the dataset is "Nothing".

The
> > dataset is Dim'ed to be available throughout the form. Other variables
> > dim'ed at that same point are fine and can be used within the button

click
> > event.
> >
> > What is closing my dataset?
> >
> > Wayne
> >
> >
> >



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      8th Jul 2004
Thanks Greg.

I forgot about Option Strict - I'll address that ASAP. I'll also try your
code to see what happens.

Wayne

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:u%(E-Mail Removed)...
> I just tried out your code and it appeared to work fine. It saved to the
> XML file without error. (I attached my code, so you could try it yourself)
>
> I added this tiny bit of code (below) to the Form_Load have some data to
> test, but that shouldn't have changed anything. Something your not
> including is causing the problem.
>
> Noticed you aren't using "Option Strict On". This will cause you headaches
> in the long run.
>
> Greg
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> ds1 = New DataSet
> Dim dt As New DataTable("CGShows")
> dt.Columns.Add("column1")
> Dim row As DataRow
> row = dt.NewRow
> row("column1") = "test"
> dt.Rows.Add(row)
> ds1.Tables.Add(dt)
>
> 'Load the data
>
> '.........................
>
> DataGrid1.DataSource = ds1
>
> DataGrid1.DataMember = "CGShows" '<= ds1 is fine here
>
> 'Wait for user to Click Button
>
> End Sub
>
>
>



 
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
Unable to cast object of type 'System.Data.DataSet' to Typed DataSet Optimus Microsoft VB .NET 1 31st Jan 2006 06:26 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 7 9th Dec 2003 02:50 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 2 31st Oct 2003 01:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 02:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 AM.