Results 1 to 13 of 13

Thread: Returning a dataset from a componant [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Returning a dataset from a componant [RESOLVED]

    Hi all ive got this class of

    VB Code:
    1. #Region "Data set"
    2.         Public Function GetDataSet()
    3.             Try
    4.                 Dim myCommand As SqlCommand = New SqlCommand
    5.                 Dim myReader As SqlDataReader = myCommand.ExecuteReader
    6.                 With myCommand
    7.                     .Connection = MyConnection
    8.                     .CommandType = CommandType.StoredProcedure
    9.                     .CommandText = "GetAllLetters"
    10.                 End With
    11.  
    12.                 Return myReader
    13.  
    14.                 Return True
    15.             Catch ex As Exception
    16.                 mErrorMsg = ex.ToString
    17.                 Return False
    18.             End Try
    19.         End Function
    20. #End Region

    Which should hopefully just return me a dataset which i wana bind to a combo box
    VB Code:
    1. Dim objData As DesignerDI.GetDI
    2.  Me.cboLetter.DataSource = objData.GetDataSet
    How can i bind it to the control ?
    Last edited by carlblanchard; Jan 29th, 2004 at 04:04 AM.
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Are you talking about ASP.NET? If not then you can't bind to a Datareader you'll need to have GetDataSet actually return a dataset. The way you have it now it returns a boolean as an object. It should be more along this line:
    VB Code:
    1. #Region "Data set"
    2.         Public Function GetDataSet() As DataSet
    3.             Try
    4.                 'where is MyConnection declared?
    5.                 Dim myCommand As New SqlCommand(MyConnection,"GetAllLatters")
    6.                 myCommand.CommandType = CommandType.StoredProcedure
    7.                 Dim da As New SqlDataAdapter(myCommand)
    8.                 Dim ds As New DataSet
    9.                 da.Fill(ds)
    10.  
    11.                 Return ds
    12.             Catch ex As Exception
    13.                 mErrorMsg = ex.ToString
    14.                 Return Nothing
    15.             End Try
    16.         End Function
    17. #End Region

    I didn't double check my syntax but it should give you the idea.

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    cheers Edneeis

    But how can i bind it to the control ???
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What you had was fine you just need to set the display member.
    VB Code:
    1. Dim objData As DesignerDI.GetDI
    2. Me.cboLetter.DataSource = objData.GetDataSet
    3. Me.cboLetter.DisplayMember="Fieldnametoshow"

  5. #5

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    thanks mate
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  6. #6

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    edneeis any ideas what this means (System.Data.DataViewManagerListItemTypeDescriptor)
    thats whats coming up in the combo box ???
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  7. #7

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    edneeis any ideas what this means (System.Data.DataViewManagerListItemTypeDescriptor)
    thats whats coming up in the combo box ???
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It means it didn't find the field that you set as the DisplayMember so it defaulted to the object's ToString method. Check what you have as the Displaymember, make sure its spelled right and it is also case sensitive (so "name" and "Name" aren't the same). You can also try setting the Displaymember before the Datasource even though it shouldn't matter either way.

  9. #9

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Code within my COM

    VB Code:
    1. #Region "Data set"
    2.         Public Function GetDataSet() As DataSet
    3.             Try
    4.                 Dim myCommand As New SqlCommand("GetAllLetters", MyConnection)
    5.                 myCommand.CommandType = CommandType.StoredProcedure
    6.                 Dim da As New SqlDataAdapter(myCommand)
    7.                 Dim ds As New DataSet
    8.                 da.Fill(ds)
    9.                 Return ds
    10.  
    11.             Catch ex As Exception
    12.                 mErrorMsg = ex.ToString
    13.                 Return Nothing
    14.             End Try
    15.         End Function
    16. #End Region

    heres the code in my onLoad function

    VB Code:
    1. Private Sub Designer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim objData As New NewForestMortgagesAPP.DesignerDI.GetDI
    3.         Me.cboLetter.DisplayMember = "Id"
    4.         Me.cboLetter.DataSource = objData.GetDataSet
    5.  
    6.     End Sub

    Attached is query showing the names of the columns ive made sure there case and still same message
    Attached Images Attached Images  
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    My bad we never assigned a table to the binding. We have to pick a table in the dataset that has the Id field and use that as the datasource or optionally you could add it to the displaymember. So if there is only 1 table in the dataset then try this:

    Me.cboLetter.DataSource = objData.GetDataSet.Tables(0)

    Otherwise use the tablename of index number of the table in the dataset which has the "Id" field you want to bind to. This happens because a dataset object can hold multiple tables and we never said which one to bind to.

  11. #11

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    OK cool thats sorted it now (THANK YOU EVER SO MUCH MATE)

    Now its binded is there a easy way to show a value but have an onChange and set an int

    ie. the combo is loading all the letters from db and of course i wana show them by name but when they select a letter i need to call my getSpeficRecord by the id of the record so is there an easy way to get that id now its binded ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The id should just be the text so you can use the SelectionChangeCommited or SelectedIndexChanged events to detect a change and just use the current text as the id.

  13. #13

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Hi edinees

    Cant really use the ID as a visual display users wouldnt have a clue

    cant i use the ValueMember element of the combo box to store the id of the record SO when they select a value it returns my db id as the valueMember ???

    VB Code:
    1. Dim objFields As New NewForestMortgagesAPP.DesignerDI.ComboPopulation
    2.         objFields.ComboId = Me.cboEditItem.SelectedIndex
    3.  
    4.         Me.cboFields.DisplayMember = "ItemText"
    5.         Me.cboFields.ValueMember = "ItemCode"
    6.         Me.cboFields.DataSource = objFields.GetDataSet.Tables(0)
    7.         objFields = Nothing

    If so how do i set the value member to get the id from the dataset ItemCode is the returned record from my query
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width