Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

trying to populate a datagrid in a windows form.

using the clsDataSet to return a dataset as below:

 

The function PopulateAuthorsGrid() is called from the windows form i.e. PopulateAuthorsDataGrid

 

Can you see why I get this error:

can't create a child list for field authors.

The datagrid does not expand, I have to click on the plus sign to expand it.

 

Thank you

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

       PopulateAuthorsDataGrid()
   End Sub


'This procedure calls the clsDataSet to return a dataset for the datagrid...
   Private Sub PopulateAuthorsDataGrid()
       Dim oDataset As clsDataSet

       Try
           oDataset = New clsDataSet()

           DataGrid1.DataSource = oDataset.PopulateAuthorsGrid()
           DataGrid1.DataMember = "authorts"

       Catch oEx As Exception
           MessageBox.Show(oEx.Message)
       End Try
   End Sub

'clsDataSet...
Public Function PopulateAuthorsGrid() As DataSet

       Dim da As SqlDataAdapter
       Dim ds As DataSet
       Dim oCon As SqlConnection
       Dim strSQL As String

       strSQL = "SELECT au_lname, au_fname, title, price"
       strSQL &= " FROM authors"
       strSQL &= " INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id"
       strSQL &= " INNER JOIN titles ON titleauthor.title_id = titles.title_id"
       strSQL &= " ORDER BY au_lname, au_fname"

       Try
           oCon = New SqlConnection(ConnectToDB)
           da = New SqlDataAdapter(strSQL, oCon)

           ds = New DataSet()
           oCon.Open()
           da.Fill(ds, "authors")
           oCon.Close()
       Catch
           Throw
       End Try

       Return ds
   End Function

Edited by Robby
Farshad

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...