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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to create an empty tableAdapter or deliver a tableAdapter to extern function

How to create an empty tableAdapter or deliver a tableAdapter to extern function

Scheduled Pinned Locked Moved C#
questiondatabasetutorialannouncement
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.
  • R Offline
    R Offline
    Robert Konig
    wrote on last edited by
    #1

    Hello community! I'm new here. My Question is: Is it possible to create a TableAdapter programmatically or deliver it to an extern function? The reason: I want to create an Class Library which should take care of DataBase activities in my application. One reason is a function i wrote that compares the loaded Row with the Row in DataBase before sending an Update-Command, which i want to use in all applications. My consideration: The Library contains an class "DBCaretaker". On creating this class, it receives the DataSet and the TableAdapters. After that, filling DataSets, Updating Tables and further actions will be executed by functions in this Library. Is this possible? Or do you have an alternative proposal? Greetings, Robert

    M 1 Reply Last reply
    0
    • R Robert Konig

      Hello community! I'm new here. My Question is: Is it possible to create a TableAdapter programmatically or deliver it to an extern function? The reason: I want to create an Class Library which should take care of DataBase activities in my application. One reason is a function i wrote that compares the loaded Row with the Row in DataBase before sending an Update-Command, which i want to use in all applications. My consideration: The Library contains an class "DBCaretaker". On creating this class, it receives the DataSet and the TableAdapters. After that, filling DataSets, Updating Tables and further actions will be executed by functions in this Library. Is this possible? Or do you have an alternative proposal? Greetings, Robert

      M Offline
      M Offline
      Morgs Morgan
      wrote on last edited by
      #2

      If you say:

      public DataSet GetUsers()
      {
      SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Users", connectionstring);
      DataSet dataset = new DataSet();
      adapter.Fill(dataset, "Users");
      return dataset;
      }

      Here you would rather want to pass the dataset to extern function and make sure the receiving function is requesting for a dataset to be returned e.g

      DateSet datasetfromfrontend = NameOfClass.GetUsers();//calling the method above

      This will return a dataset and you can check for tables e.g

      DataTable table = datasetfromfrontend.Tables[0];

      Good luck

      R 1 Reply Last reply
      0
      • M Morgs Morgan

        If you say:

        public DataSet GetUsers()
        {
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Users", connectionstring);
        DataSet dataset = new DataSet();
        adapter.Fill(dataset, "Users");
        return dataset;
        }

        Here you would rather want to pass the dataset to extern function and make sure the receiving function is requesting for a dataset to be returned e.g

        DateSet datasetfromfrontend = NameOfClass.GetUsers();//calling the method above

        This will return a dataset and you can check for tables e.g

        DataTable table = datasetfromfrontend.Tables[0];

        Good luck

        R Offline
        R Offline
        Robert Konig
        wrote on last edited by
        #3

        This way i could go, but i wanted something little different: I don't want to create an adapter with just one SELECT command, rather i would like to go on something like this: public void myFunction(DataSet myDataSet, "TableAdapter" myTableAdapter) { // working with both } Or this: public void myFunction(DataSet myDataSet) { "TableAdapter" myTableAdapter = myDataSetTableAdapterCollection.TableAdapter[0]; } Then i could use all the SQL commands of this TableAdapter, and don't have to write them manually.

        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