Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. passing a dataset...where's my data?

passing a dataset...where's my data?

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leezardd
    wrote on last edited by
    #1

    I am trying to separate my data access code from my form code. I have a created a data access class containing a function to accept an EmployeeID and return a dataset containing just information for that employee. When I try to display the employee information on the form I am getting the column name rather than the value contained in the column. What am I doing wrong? Form Code Private Sub frmMaint_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Try dsSpcInstrFRM = m_DAL.SpecialInstructions(strEmpIdFromChooseFrm) dtSpcInstrFRM = dsSpcInstrFRM.Tables("SpcInstructions") lblSpcInstructions.Text = dtSpcInstrFRM.Columns("SpcInstr").ToString Catch ex As Exception ‘Error Routine End Try End Sub Data Access Code Friend Function SpecialInstructions(ByVal m_strEmpID As String) As Dataset Dim sqlRiskDR As SqlDataReader Dim SpecialInstructionsDS As New DataSet Dim SpcInstrDT As New DataTable Dim SpcInstrDR As DataRow Try sqlRiskCN = New SqlConnection(My.Settings.SQLRiskCNString) sqlRiskCN.Open() 'Use Stored Procedure strSql = "GetSpecialInstructions " & "'" & m_strEmpID & " '" sqlCM = New SqlCommand(strSql, sqlRiskCN) sqlRiskDR = sqlCM.ExecuteReader() SpecialInstructionsDS.DataSetName = "SpecialInstructions" SpecialInstructionsDS.Tables.Add(SpcInstrDT) SpcInstrDT.TableName = "SpcInstructions" SpcInstrDT.Columns.Add("EmpID").Unique = False SpcInstrDT.Columns.Add("SpcInstr") Do While sqlRiskDR.Read() SpcInstrDR = SpcInstrDT.NewRow SpcInstrDR.Item("EmpID") = sqlRiskDR.Item("EmpID").ToString SpcInstrDR.Item("SpcInstr") = sqlRiskDR.Item("EmergInstructions").ToString.TrimEnd SpcInstrDT.Rows.Add(SpcInstrDR) Loop sqlRiskDR.Close() sqlRiskCN.Close() Catch ex As Exception ‘Error Routine End Try Return SpecialInstructionsDS End Function

    G 1 Reply Last reply
    0
    • L leezardd

      I am trying to separate my data access code from my form code. I have a created a data access class containing a function to accept an EmployeeID and return a dataset containing just information for that employee. When I try to display the employee information on the form I am getting the column name rather than the value contained in the column. What am I doing wrong? Form Code Private Sub frmMaint_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Try dsSpcInstrFRM = m_DAL.SpecialInstructions(strEmpIdFromChooseFrm) dtSpcInstrFRM = dsSpcInstrFRM.Tables("SpcInstructions") lblSpcInstructions.Text = dtSpcInstrFRM.Columns("SpcInstr").ToString Catch ex As Exception ‘Error Routine End Try End Sub Data Access Code Friend Function SpecialInstructions(ByVal m_strEmpID As String) As Dataset Dim sqlRiskDR As SqlDataReader Dim SpecialInstructionsDS As New DataSet Dim SpcInstrDT As New DataTable Dim SpcInstrDR As DataRow Try sqlRiskCN = New SqlConnection(My.Settings.SQLRiskCNString) sqlRiskCN.Open() 'Use Stored Procedure strSql = "GetSpecialInstructions " & "'" & m_strEmpID & " '" sqlCM = New SqlCommand(strSql, sqlRiskCN) sqlRiskDR = sqlCM.ExecuteReader() SpecialInstructionsDS.DataSetName = "SpecialInstructions" SpecialInstructionsDS.Tables.Add(SpcInstrDT) SpcInstrDT.TableName = "SpcInstructions" SpcInstrDT.Columns.Add("EmpID").Unique = False SpcInstrDT.Columns.Add("SpcInstr") Do While sqlRiskDR.Read() SpcInstrDR = SpcInstrDT.NewRow SpcInstrDR.Item("EmpID") = sqlRiskDR.Item("EmpID").ToString SpcInstrDR.Item("SpcInstr") = sqlRiskDR.Item("EmergInstructions").ToString.TrimEnd SpcInstrDT.Rows.Add(SpcInstrDR) Loop sqlRiskDR.Close() sqlRiskCN.Close() Catch ex As Exception ‘Error Routine End Try Return SpecialInstructionsDS End Function

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Because you are reading the value from the column information in the data set, not from the data rows. Use the Rows property. --- b { font-weight: normal; }

      L 1 Reply Last reply
      0
      • G Guffa

        Because you are reading the value from the column information in the data set, not from the data rows. Use the Rows property. --- b { font-weight: normal; }

        L Offline
        L Offline
        leezardd
        wrote on last edited by
        #3

        Using the rows property makes sense, but now it brings up the question of how I actually retrieve the data from the dataset. As you can probably tell I am new at this. What code do I need to add to my form to get this to work? Thanks!

        T 1 Reply Last reply
        0
        • L leezardd

          Using the rows property makes sense, but now it brings up the question of how I actually retrieve the data from the dataset. As you can probably tell I am new at this. What code do I need to add to my form to get this to work? Thanks!

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          lblSpcInstructions.Text = dtSpcInstrFRM.Items("SpcInstr").ToString Go here for more info "People who never make mistakes, never do anything." My Blog

          L 1 Reply Last reply
          0
          • T ToddHileHoffer

            lblSpcInstructions.Text = dtSpcInstrFRM.Items("SpcInstr").ToString Go here for more info "People who never make mistakes, never do anything." My Blog

            L Offline
            L Offline
            leezardd
            wrote on last edited by
            #5

            Using item still places SpcInstr in the text of the label. I am trying to get the value from the column named "SpcInstr". Any other suggestions?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups