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. saving data problem when using function for dataadapter and data set

saving data problem when using function for dataadapter and data set

Scheduled Pinned Locked Moved Visual Basic
helptutorialannouncement
3 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

    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. When i am saving data , and i call CISCLASS.daCISCntrct.update(CISCLASS.dsCIScntrct,"Table_Name")..it goes to function and initialize datadapter and not saving new data . it not giving me error but if i look at table, it has all old data where as if i write this code in private sub procedure , its saving data and next time i see new data in the table. Please reply me asap. Thanks in adavance.

    D 1 Reply Last reply
    0
    • H hemrk

      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. When i am saving data , and i call CISCLASS.daCISCntrct.update(CISCLASS.dsCIScntrct,"Table_Name")..it goes to function and initialize datadapter and not saving new data . it not giving me error but if i look at table, it has all old data where as if i write this code in private sub procedure , its saving data and next time i see new data in the table. Please reply me asap. Thanks in adavance.

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

      You've posted this question numerous times now and I do believe you've been given the answer.   If you don't understand the answer reply to the original post and seek clarification. Anyway, the simple way is to change the function to a sub with two parameters, one of type DataSet and the other of type DataAdapter.   Mark these parameters with the ByRef keyword (I think, I haven't done VB for quite some time) and then when you call the sub pass in an empty dataset and an empty data adapter.   Inside of the sub, before you exit and at the same time as you would normally return, set the parameters to the values of daCISCntrct and dsCISCntrct, they will then be available to the calling function.

      H 1 Reply Last reply
      0
      • D DoctorMick

        You've posted this question numerous times now and I do believe you've been given the answer.   If you don't understand the answer reply to the original post and seek clarification. Anyway, the simple way is to change the function to a sub with two parameters, one of type DataSet and the other of type DataAdapter.   Mark these parameters with the ByRef keyword (I think, I haven't done VB for quite some time) and then when you call the sub pass in an empty dataset and an empty data adapter.   Inside of the sub, before you exit and at the same time as you would normally return, set the parameters to the values of daCISCntrct and dsCISCntrct, they will then be available to the calling function.

        H Offline
        H Offline
        hemrk
        wrote on last edited by
        #3

        i understand that bu the problem now is its not saving the data when i say da.update and ds.aceeptchanges. as when i call the da.update, it goes to da function and initialize evetything so doesnt change values in table. how to do update and acceptchanges to the table

        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