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. Windows Forms
  4. how return Dataadapter and dataset from function in class file for multiple use

how return Dataadapter and dataset from function in class file for multiple use

Scheduled Pinned Locked Moved Windows Forms
tutorialannouncement
2 Posts 2 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.
  • H Offline
    H Offline
    hemrk
    wrote on last edited by
    #1

    i have created function in class file. Public Shared Function dsCntrctET() As DataSet Dim sqlCntrct As String = "Select * from CNTRCT_ET where CNTRCT_ID=" & CISCNO Dim cmdCISContract As New OracleCommand Dim daCISCntrct As New OracleDataAdapter Dim dsCISCntrct As New DataSet Dim cmdCISBuilder As New OracleCommandBuilder Try With cmdCISContract .Transaction = myTransCIS .CommandText = sqlCntrct .Connection = cnCIS End With daCISCntrct = New OracleDataAdapter(cmdCISContract) daCISCntrct.FillSchema(dsCISCntrct, SchemaType.Source) cmdCISBuilder = New OracleCommandBuilder(daCISCntrct) With daCISCntrct .TableMappings.Add("Table", "CNTRCT_ET") .Fill(dsCISCntrct) .SelectCommand = cmdCISContract .InsertCommand = cmdCISBuilder.GetInsertCommand .UpdateCommand = cmdCISBuilder.GetUpdateCommand .DeleteCommand = cmdCISBuilder.GetDeleteCommand End With Catch ex As Exception MessageBox.Show(ex.Message) End Try Return (dsCISCntrct) End Function it returns dataset that i can use for getting value from table. but while saving data, i have to use dataadapter for da.update(ds,"table") and ds.acceptchanges. this i have to use in multiple forms as this data comes from 3rd party so i dont want to write this in every form . so i thought how to return data adapter and dataset from the same function. as i wanted to use daCISCntrct and dsCISCntrct.

    D 1 Reply Last reply
    0
    • H hemrk

      i have created function in class file. Public Shared Function dsCntrctET() As DataSet Dim sqlCntrct As String = "Select * from CNTRCT_ET where CNTRCT_ID=" & CISCNO Dim cmdCISContract As New OracleCommand Dim daCISCntrct As New OracleDataAdapter Dim dsCISCntrct As New DataSet Dim cmdCISBuilder As New OracleCommandBuilder Try With cmdCISContract .Transaction = myTransCIS .CommandText = sqlCntrct .Connection = cnCIS End With daCISCntrct = New OracleDataAdapter(cmdCISContract) daCISCntrct.FillSchema(dsCISCntrct, SchemaType.Source) cmdCISBuilder = New OracleCommandBuilder(daCISCntrct) With daCISCntrct .TableMappings.Add("Table", "CNTRCT_ET") .Fill(dsCISCntrct) .SelectCommand = cmdCISContract .InsertCommand = cmdCISBuilder.GetInsertCommand .UpdateCommand = cmdCISBuilder.GetUpdateCommand .DeleteCommand = cmdCISBuilder.GetDeleteCommand End With Catch ex As Exception MessageBox.Show(ex.Message) End Try Return (dsCISCntrct) End Function it returns dataset that i can use for getting value from table. but while saving data, i have to use dataadapter for da.update(ds,"table") and ds.acceptchanges. this i have to use in multiple forms as this data comes from 3rd party so i dont want to write this in every form . so i thought how to return data adapter and dataset from the same function. as i wanted to use daCISCntrct and dsCISCntrct.

      D Offline
      D Offline
      DoctorMick
      wrote on last edited by
      #2

      Don't cross post in multiple forums. Have a look at out parameters.

      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