Jump to content
Xtreme .Net Talk

Database choice?


Recommended Posts

Posted (edited)

You have a syntax error

 

Orion,

 

You have the correct code but you inserted it wrong.

First thing, you mispelled your variable "DVlog" . You typed:

DVblog.ReadXml(myXmlReader)

 

Secondly, and most importantly, you didnt have your code within a subroutine (Sub).

 

You have the first part of your code inside a subroutine (SaveXML)

Private Sub saveXMLFile()
       DVlog.ReadXml(fileOpen)
       Dim sDialog As New SaveFileDialog()
       sDialog.FileName = ("DVconfig") & ".xml"
       sDialog.Filter = "XML files (*.xml)|*.xml"
       If sDialog.ShowDialog = DialogResult.OK Then
           Dim wstream As New _
           System.IO.StreamWriter(sDialog.FileName)
           DVlog.WriteXml(wstream, XmlWriteMode.WriteSchema)
           wstream.Close()
       End If
   End Sub

 

but the rest is not:

 

    ViewDVlog.datasource = ds1 
   ViewDVlog.readonly = true 

   Dim fsReadXml As New System.IO.FileStream("DVconfig.xml", System.IO.FileMode.Open)
   ' Create an XmlTextReader to read the file. 
   Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
   ' Read the XML document into the DataSet. 
   DVblog.ReadXml(myXmlReader) 
   ' Close the XmlTextReader 
   myXmlReader.Close() 
End Class

 

Do you understand what I mean? You have to have the above code inside a Sub... end Sub. Visual Basic will not recognize your variables otherwise.

 

What i do is I have a button that when pressed will load the xml into the datagrid when i press it. SO it should look something like this:

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Dim fsReadXml As New System.IO.FileStream("DVconfig.xml", System.IO.FileMode.Open)
   ' Create an XmlTextReader to read the file. 
   Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
   ' Read the XML document into the DataSet. 
   DVlog.ReadXml(myXmlReader) 
   ' Close the XmlTextReader 
   myXmlReader.Close() 

End Sub

In other words... create a button on your form, and then double click it. The code will come up. Then place the code inside there.

You can also place the code in the Load Sub procedure if you want it to do it automatically when the program starts. Whatever, but the main thing is that it HAS to be within a sub procedure

 

THe code you use to set the datagrid to read-only also has to be inside a sub procedure. So maybe put it in the Sub Load procedure or set it at design time.

 

If you get this correct the code will work. If for some reason it is not finding your xml file, then you can try and use a fileOpenDialog to show it where the file is. But you can cross that bridge when you come to it.

 

Let me know how it goes!

 

jim

Edited by Flyguy
Posted (edited)

oops.. i forgot to mention what to do with this important line of code:

ViewDVlog.datasource = ds1

 

you should put that with the rest of the code as shown below (or even better put it in your form load procedure):

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

[u]ViewDVlog.datasource = ds1[/u]
Dim fsReadXml As New System.IO.FileStream("DVconfig.xml", System.IO.FileMode.Open) 
' Create an XmlTextReader to read the file. 
Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml) 
' Read the XML document into the DataSet. 
DVlog.ReadXml(myXmlReader) 
' Close the XmlTextReader 
myXmlReader.Close() 

End Sub 

Edited by Flyguy
Guest Orion Tatsihama
Posted
Thanks because your first directions confused the crap out of me. Let me do this and I'll update ya.
Guest Orion Tatsihama
Posted (edited)
Problem, in the:
 Private Sub saveXMLFile()
       DVlog.ReadXml(FileOpen)
       Dim sDialog As New SaveFileDialog()
       sDialog.FileName = ("DVconfig") & ".xml"
       sDialog.Filter = "XML files (*.xml)|*.xml"
       If sDialog.ShowDialog = DialogResult.OK Then
           Dim wstream As New _
           System.IO.StreamWriter(sDialog.FileName)
           DVlog.WriteXml(wstream, XmlWriteMode.WriteSchema)
           wstream.Close()
       End If
   End Sub

The DVlog.ReadXml(FileOpen) has an error at FileOpen. It says: Argument not specified for parameter...blah blah blah.

Edited by Derek Stone
Posted

fileOpen = ?

 

Right... because FileOpen needs to be specified. It is just a variable to hold the file location (i.e. "mySchema.xsd")

 

Second of all it doesnt belong in your Sub SaveXMLFile procedure:

 

it belongs in your load procedure like follows:

 

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

 

DVlog.ReadXml(FileOpen)

 

but dont actually type "FileOpen".. put your schema (.xsd) location there: for example: DVlog.ReadXML("xmlSchema.xsd")

This loads the xml schema that you created into your dataset.

 

 

Im sorry that i didn't catch (and repeated) your placement mistake on the last message.

 

jim

Guest Orion Tatsihama
Posted
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       DVlog.ReadXml(xmlSchema.xsd)
   End Sub

Has an error at xmlSchema (which is what my xml schema is called). It says something about: 'System.Data.XMLSchema' is not accessible in this context because it is 'Private'

Posted

because you have to put xmlSchema.xsd in parantheses. Like this:

 

DVlog.ReadXML("xmlSchema.xsd")

Guest Orion Tatsihama
Posted
Public Class Form
   Inherits System.Windows.Forms.Form

   Public DVlog As New DataSet()
   Dim xmlDoc As New Xml.XmlDataDocument()



#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 Cancel As System.Windows.Forms.Button
   Friend WithEvents Submit As System.Windows.Forms.Button
   Friend WithEvents DVDProps As System.Windows.Forms.GroupBox
   Friend WithEvents Comments As System.Windows.Forms.TextBox
   Friend WithEvents Year As System.Windows.Forms.TextBox
   Friend WithEvents SE As System.Windows.Forms.ComboBox
   Friend WithEvents Disks As System.Windows.Forms.TextBox
   Friend WithEvents Length As System.Windows.Forms.TextBox
   Friend WithEvents Rating As System.Windows.Forms.ComboBox
   Friend WithEvents Title As System.Windows.Forms.TextBox
   Friend WithEvents Genre As System.Windows.Forms.TextBox
   Friend WithEvents CommentsLabel As System.Windows.Forms.Label
   Friend WithEvents YearLabel As System.Windows.Forms.Label
   Friend WithEvents SELabel As System.Windows.Forms.Label
   Friend WithEvents DisksLabel As System.Windows.Forms.Label
   Friend WithEvents LengthLabel As System.Windows.Forms.Label
   Friend WithEvents RatingLabel As System.Windows.Forms.Label
   Friend WithEvents TitleLabel As System.Windows.Forms.Label
   Friend WithEvents GenreLabel As System.Windows.Forms.Label
   Friend WithEvents ViewDVlog As System.Windows.Forms.DataGrid
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Cancel = New System.Windows.Forms.Button()
       Me.Submit = New System.Windows.Forms.Button()
       Me.DVDProps = New System.Windows.Forms.GroupBox()
       Me.Comments = New System.Windows.Forms.TextBox()
       Me.Year = New System.Windows.Forms.TextBox()
       Me.SE = New System.Windows.Forms.ComboBox()
       Me.Disks = New System.Windows.Forms.TextBox()
       Me.Length = New System.Windows.Forms.TextBox()
       Me.Rating = New System.Windows.Forms.ComboBox()
       Me.Title = New System.Windows.Forms.TextBox()
       Me.Genre = New System.Windows.Forms.TextBox()
       Me.CommentsLabel = New System.Windows.Forms.Label()
       Me.YearLabel = New System.Windows.Forms.Label()
       Me.SELabel = New System.Windows.Forms.Label()
       Me.DisksLabel = New System.Windows.Forms.Label()
       Me.LengthLabel = New System.Windows.Forms.Label()
       Me.RatingLabel = New System.Windows.Forms.Label()
       Me.TitleLabel = New System.Windows.Forms.Label()
       Me.GenreLabel = New System.Windows.Forms.Label()
       Me.ViewDVlog = New System.Windows.Forms.DataGrid()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.GroupBox1 = New System.Windows.Forms.GroupBox()
       Me.DVDProps.SuspendLayout()
       CType(Me.ViewDVlog, System.ComponentModel.ISupportInitialize).BeginInit()
       Me.GroupBox1.SuspendLayout()
       Me.SuspendLayout()

       [i took out a bunch of Form Designer code to shorten message]

       '
       'RatingLabel
       '
       Me.RatingLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl
       Me.RatingLabel.Location = New System.Drawing.Point(192, 72)
       Me.RatingLabel.Name = "RatingLabel"
       Me.RatingLabel.Size = New System.Drawing.Size(40, 16)
       Me.RatingLabel.TabIndex = 3
       Me.RatingLabel.Text = "Rating"
       '
       'TitleLabel
       '
       Me.TitleLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl
       Me.TitleLabel.Location = New System.Drawing.Point(8, 72)
       Me.TitleLabel.Name = "TitleLabel"
       Me.TitleLabel.Size = New System.Drawing.Size(32, 16)
       Me.TitleLabel.TabIndex = 2
       Me.TitleLabel.Text = "Title"
       '
       'GenreLabel
       '
       Me.GenreLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl
       Me.GenreLabel.Location = New System.Drawing.Point(8, 32)
       Me.GenreLabel.Name = "GenreLabel"
       Me.GenreLabel.Size = New System.Drawing.Size(40, 16)
       Me.GenreLabel.TabIndex = 1
       Me.GenreLabel.Text = "Genre"
       '
       'ViewDVlog
       '
       Me.ViewDVlog.DataMember = ""
       Me.ViewDVlog.HeaderForeColor = System.Drawing.SystemColors.ControlText
       Me.ViewDVlog.Location = New System.Drawing.Point(360, 8)
       Me.ViewDVlog.Name = "ViewDVlog"
       Me.ViewDVlog.Size = New System.Drawing.Size(368, 416)
       Me.ViewDVlog.TabIndex = 10
       '
       'Button1
       '
       Me.Button1.Location = New System.Drawing.Point(168, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.Size = New System.Drawing.Size(72, 32)
       Me.Button1.TabIndex = 11
       Me.Button1.Text = "Refresh"
       '
       'GroupBox1
       '
       Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Cancel, Me.Submit, Me.Button1})
       Me.GroupBox1.Location = New System.Drawing.Point(56, 368)
       Me.GroupBox1.Name = "GroupBox1"
       Me.GroupBox1.Size = New System.Drawing.Size(248, 56)
       Me.GroupBox1.TabIndex = 12
       Me.GroupBox1.TabStop = False
       Me.GroupBox1.Text = "Controls"
       '
       'Form
       '
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(736, 430)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1, Me.ViewDVlog, Me.DVDProps})
       Me.Name = "Form"
       Me.Text = "DVLog"
       Me.DVDProps.ResumeLayout(False)
       CType(Me.ViewDVlog, System.ComponentModel.ISupportInitialize).EndInit()
       Me.GroupBox1.ResumeLayout(False)
       Me.ResumeLayout(False)

       '
       'Dataset
       '
       ViewDVlog.DataSource = DVlog
       ViewDVlog.ReadOnly = True
   End Sub

At the ViewDVlog.DataSource = DVlog it says: The variable 'DVlog' is either undeclared or was never assigned.

Posted

argh!

Ok... you put it in the wrong place again.

Dont even mess with the code you showed above.

Dont even expand the "#Region " Windows Form Designer generated code ". You don't need it and wont even touch it.

 

Do this... go to your form where you can see the actual way it looks... double click somewhere on the form (not on a button or datagrid.. but just on the blank form)...

the code window will come up and you will be inside of " Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load"

 

Put, your code THERE.

 

ViewDVlog.dataSource = DVlog

ViewDVlog.ReadOnly = true

 

make sure its BETWEEN sub form1_load (etc...)

and

end sub

 

 

Also make sure you delete it out of the wrong place you put it.

jim

Guest Orion Tatsihama
Posted
Don't get all mad...just be more specific cause I have no idea what is what.
Guest Orion Tatsihama
Posted

Now when I try to debug/test the program, I get this:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.xml.dll

 

Additional information: Could not find file "H:\Documents and Settings\Orion\My Documents\Visual Studio Projects\DVlog\bin\xmlSchema.xsd".

 

At this line: DVlog.ReadXml("xmlSchema.xds")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       DVlog.ReadXml("xmlSchema.xsd")
       ViewDVlog.DataSource = DVlog
       ViewDVlog.ReadOnly = True
   End Sub

And xmlSchema.xsd is the name of my schema.

Posted

i wasn't mad... if i was mad I wouldnt respond anymore :)

Now, read your error and see if you can figure out what the problem is:

Could not find file "H:\Documents and Settings\Orion\My Documents\Visual Studio Projects\DVlog\bin\xmlSchema.xsd".

 

So obviously its not able to find the file "xmlSchema.xsd"... did you create a xsd file the way i explained it?

Secondly, if you did and its not in the directory that the program is looking for it in, then either, 1) move it to that directory (short term answer) or 2) create an openFIleDialog and navigate to it.

 

I suggest that for the sake of initially getting the program to work that you just move the file to the directory that it's looking for it in. ("H:\Documents and Settings\Orion\My Documents\Visual Studio Projects\DVlog\bin\") - And then AFTER you have had the program work succesfully worry about making a more reasonable way of finding files.

 

let me know,

 

jim

Guest Orion Tatsihama
Posted
I don't even know where the file is...I created it just like you told me. And when this program is released, wouldn't having a Save and Open file dialogue enable multiple databases?
Posted

try doing a windows search for the file...

dont worry about creating a Save or Open file dialogue right now. Just get the program working first...

 

BUT what a open file dialogue would do is allow the user to navigate to where the file is. You would tie it into the button that you click to load the file. But again.. dont worry about that yet because we dont need to go down that rabbit trail yet. Lets get the program working.

 

jim

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...