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. Database & SysAdmin
  3. Database
  4. Should i use SqlConnection or SqlDataAdapter Only ?

Should i use SqlConnection or SqlDataAdapter Only ?

Scheduled Pinned Locked Moved Database
questiondatabasecomsysadmintutorial
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.
  • K Offline
    K Offline
    kakarato
    wrote on last edited by
    #1

    Should i use SqlConnection to connect to server before i use SqlDataAdapter to to fill the dataset ? Example : ============= string ConStr = "server=(local);uid=sa;pwd=password;database=NorthWind"; string cmdString = "select top 3 last name, firstname, title from employees"; SqlConnection conn = new SqlConnection(ConStr); SqlCommand com = new SqlCommand(cmdString,con); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); conn.open(); // Even without conn.open i stll able to fill the da. da.Fill(ds); I try code above and i found that even without manuall open the connection i still able to fill up the dataadapter (da). So what is the best method to fill the dataadapter with out connection first out without using connection?

    C 1 Reply Last reply
    0
    • K kakarato

      Should i use SqlConnection to connect to server before i use SqlDataAdapter to to fill the dataset ? Example : ============= string ConStr = "server=(local);uid=sa;pwd=password;database=NorthWind"; string cmdString = "select top 3 last name, firstname, title from employees"; SqlConnection conn = new SqlConnection(ConStr); SqlCommand com = new SqlCommand(cmdString,con); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); conn.open(); // Even without conn.open i stll able to fill the da. da.Fill(ds); I try code above and i found that even without manuall open the connection i still able to fill up the dataadapter (da). So what is the best method to fill the dataadapter with out connection first out without using connection?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      If your connection is closed already - the DataAdapter will open the connection, perform the query, and close the connection again. If you do not need the connection open for anything else then I recommend you let the DataAdapter do the clean up for you. [ADDITIONAL] I should add that if the connection is already open the DataAdapter will not close it [/ADDITIONAL] If you are going to perform a series of queries one-after-the-other then I would recommend that you open the connection, perform your queries, then close the connection. Does this help?


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      K 1 Reply Last reply
      0
      • C Colin Angus Mackay

        If your connection is closed already - the DataAdapter will open the connection, perform the query, and close the connection again. If you do not need the connection open for anything else then I recommend you let the DataAdapter do the clean up for you. [ADDITIONAL] I should add that if the connection is already open the DataAdapter will not close it [/ADDITIONAL] If you are going to perform a series of queries one-after-the-other then I would recommend that you open the connection, perform your queries, then close the connection. Does this help?


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        K Offline
        K Offline
        kakarato
        wrote on last edited by
        #3

        Thanks it really help and clear all my doubt.:-D

        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