XSD.EXE

HELP!  I'm trying to create a strongly typed dataset using the XSD.EXE.  I have managed to create a file that, once renamed (with xsd filename extension) is visible within VS.  Only problem is, i need a .vb version of this file.  I have tried the following code within my mini dataset creator app but to no avail.

    Private Sub buttonCreateSchema_Click(ByVal sender As System.Object, _
                                                ByVal e As System.EventArgs) _
                                                Handles buttonCreateSchema.Click
        Dim result As DialogResult = SaveFileDialog1.ShowDialog()
        If result = DialogResult.OK Then
            createschema(textConnectionString.Text, textTableName.Text, _
                        textXsdUtilityFilename.Text, SaveFileDialog1.FileName)
        End If

    End Sub

    Public Sub CreateSchema(ByVal connectionString As String, _
                            ByVal tableName As String, _
                            ByVal xsdUtilityFilename As String, _
                            ByVal xsdFilename As String)
        Dim connection As New SqlClient.SqlConnection(connectionString)
        Dim adapter As SqlClient.SqlDataAdapter
        Try
            connection.Open()


            adapter = New SqlClient.SqlDataAdapter("select top 1 * from " & _
                                                    tableName, connection)
            Dim dataset As New DataSet(tableName & "DataSet")
            Dim table As New DataTable(tableName)
            dataset.Tables.Add(table)
            adapter.Fill(table)

            ' Once we have the DataSet, we can write the schema to the specified filename

            dataset.WriteXmlSchema(xsdFilename)

            Dim info As New System.IO.FileInfo(xsdFilename)

            Dim commandline As String = """" & xsdFilename & _
                                        """ /d /l:vb /out:""" & _
                                        info.DirectoryName & """"

            Dim process As System.Diagnostics.Process = _
                System.Diagnostics.Process.Start(xsdUtilityFilename, commandline)
            process.WaitForExit()

            MsgBox("The new typed DataSet has been created in " & _
            info.directoryname)


        Catch ex As Exception
            MsgBox(ex.GetType().ToString & ":" & ex.Message)

        Finally
            If connection.State <> ConnectionState.Closed Then
                connection.Close()
            End If
            If Not adapter Is Nothing Then
                adapter.Dispose()
            End If
        End Try

    End Sub

For some reason, it doesn't want to create a .vb file, in fact it doesn't even include the file extension with the saved file.

I want to use the .vb file to bind an objects properties to the dataset data.  Can I do this using the .xsd file and if so, how

Can anyone point me in the right direction


Answer this question

XSD.EXE

  • Kamran Amin

    Solved it, just being a little dumb... long day at work an all.  Didn't realise you just right clicked on the class to generate the dataset.
  • DrFlick

    Hi Mark,

    It looks like you are trying to create a typed dataset based on the schema of a database table.

    Have you considered using the Server Explorer in Visual Studio .NET to do this  You could add a new Typed DataSet to your project and then, from the Server Explorer, connect to your database, find your table, and then drag and drop it on to the dataset designer surface.

    This will examine the properties of the table in the database and create the corresponding schema (and thus typed dataset) for you.

    -Paul

  • XSD.EXE