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. C#
  4. C# books

C# books

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadminquestion
8 Posts 4 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.
  • G Offline
    G Offline
    gamer1127
    wrote on last edited by
    #1

    Can someone give me some books that discusses completely microsoft visual c# 2005 with relational database particularly the ms access database? Because I have a book that has the same discussions but with sql server and with minimal ms access discussion.

    S R 2 Replies Last reply
    0
    • G gamer1127

      Can someone give me some books that discusses completely microsoft visual c# 2005 with relational database particularly the ms access database? Because I have a book that has the same discussions but with sql server and with minimal ms access discussion.

      S Offline
      S Offline
      Shadoblaque
      wrote on last edited by
      #2

      Well, one book that I have found useful is Deitel's C# for Programmers (ISBN 0-13-134591-5). That's what I started with. Concerning MS Access, here is some code that may help you get started: OleDbConnection jetDB = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + AccessFileFullPath + "'"); /// <summary> /// Handles SQL commands that do not return results, such as CREATE, /// INSERT, or DELETE. /// </summary> /// <param name="SQL">SQL command string (must terminate with semicolon).</param> public void ExecuteNonQuery(string SQL) { OleDbCommand executeCommand = new OleDbCommand(SQL, jetDB); jetDB.Open(); executeCommand.ExecuteNonQuery(); jetDB.Close(); } /// <summary> /// Retrieves data from the specified table or query, using the SQL string /// passed as a parameter. /// </summary> /// <param name="query">SQL string to execute to obtain the Data Table.</param> /// <returns>A data table populated with the specified query.</returns> public DataTable ExecuteQuery(string query) { DataTable queryResult = new DataTable(); OleDbDataAdapter queryDBA = new OleDbDataAdapter(query, jetDB); queryDBA.Fill(queryResult); return queryResult; }

      G 1 Reply Last reply
      0
      • S Shadoblaque

        Well, one book that I have found useful is Deitel's C# for Programmers (ISBN 0-13-134591-5). That's what I started with. Concerning MS Access, here is some code that may help you get started: OleDbConnection jetDB = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + AccessFileFullPath + "'"); /// <summary> /// Handles SQL commands that do not return results, such as CREATE, /// INSERT, or DELETE. /// </summary> /// <param name="SQL">SQL command string (must terminate with semicolon).</param> public void ExecuteNonQuery(string SQL) { OleDbCommand executeCommand = new OleDbCommand(SQL, jetDB); jetDB.Open(); executeCommand.ExecuteNonQuery(); jetDB.Close(); } /// <summary> /// Retrieves data from the specified table or query, using the SQL string /// passed as a parameter. /// </summary> /// <param name="query">SQL string to execute to obtain the Data Table.</param> /// <returns>A data table populated with the specified query.</returns> public DataTable ExecuteQuery(string query) { DataTable queryResult = new DataTable(); OleDbDataAdapter queryDBA = new OleDbDataAdapter(query, jetDB); queryDBA.Fill(queryResult); return queryResult; }

        G Offline
        G Offline
        gamer1127
        wrote on last edited by
        #3

        if I buy a book about sql server, will i be able to use the sql queries presented in that book to ms access?

        S 1 Reply Last reply
        0
        • G gamer1127

          if I buy a book about sql server, will i be able to use the sql queries presented in that book to ms access?

          S Offline
          S Offline
          Shadoblaque
          wrote on last edited by
          #4

          The SQL syntax is very similar, if that's what you are asking. Learning SQL is not the same thing as learning C#, of course. Here's another example that builds upon the previous one (where coreDB is a class containing the previous code, and the call to Asset is a constructor for another class in the example project that builds from the specific data row). The uppercase component in this one is the SQL used in querying MS Access. /// <summary> /// Gets the object array of inventory items. /// </summary> /// <param name="orgID">Int ID of the organization.</param> /// <returns>An arraylist of inventory item listings.</returns> public ArrayList GetOrgAssets(int orgID) { ArrayList result = new ArrayList(); DataTable assets = coreDB.ExecuteQuery ("SELECT * FROM ORGANIZATION_ASSETS WHERE ORGANIZATION_FK = "+orgID.ToString()+";"); foreach (DataRow dr in assets.Rows) result.Add(new Asset(dr)); return result; }

          D 1 Reply Last reply
          0
          • S Shadoblaque

            The SQL syntax is very similar, if that's what you are asking. Learning SQL is not the same thing as learning C#, of course. Here's another example that builds upon the previous one (where coreDB is a class containing the previous code, and the call to Asset is a constructor for another class in the example project that builds from the specific data row). The uppercase component in this one is the SQL used in querying MS Access. /// <summary> /// Gets the object array of inventory items. /// </summary> /// <param name="orgID">Int ID of the organization.</param> /// <returns>An arraylist of inventory item listings.</returns> public ArrayList GetOrgAssets(int orgID) { ArrayList result = new ArrayList(); DataTable assets = coreDB.ExecuteQuery ("SELECT * FROM ORGANIZATION_ASSETS WHERE ORGANIZATION_FK = "+orgID.ToString()+";"); foreach (DataRow dr in assets.Rows) result.Add(new Asset(dr)); return result; }

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            I don't doubt that your code works, but whenever I see ArrayList in someone's code I begin to have doubts. The OP said he had VS2005 so he will most likely be using .NET 2.0 which has generic lists List<T> which should be used instead. Also, your final foreach loop may possibly be removed by the use of the AddRange method which would be far more efficient.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            S 1 Reply Last reply
            0
            • D DaveyM69

              I don't doubt that your code works, but whenever I see ArrayList in someone's code I begin to have doubts. The OP said he had VS2005 so he will most likely be using .NET 2.0 which has generic lists List<T> which should be used instead. Also, your final foreach loop may possibly be removed by the use of the AddRange method which would be far more efficient.

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Why are you using VB6? Do you hate yourself? (Christian Graus)

              S Offline
              S Offline
              Shadoblaque
              wrote on last edited by
              #6

              List<T> could be employed here (such as List<Asset>). AddRange won't work in this case however, as it is not an ICollection that is being added.   So, while: result.AddRange(assets.Rows); would work (if Rows was to be returned), this line: result.AddRange(new Asset(dr)); would not.   (Did you miss that Asset was a class constructor with the row as a parameter?)   The returning value in this case is a collection of Asset objects (I have not defined the Asset class here, I just provided the snippet as an example of MS Access interaction).

              D 1 Reply Last reply
              0
              • S Shadoblaque

                List<T> could be employed here (such as List<Asset>). AddRange won't work in this case however, as it is not an ICollection that is being added.   So, while: result.AddRange(assets.Rows); would work (if Rows was to be returned), this line: result.AddRange(new Asset(dr)); would not.   (Did you miss that Asset was a class constructor with the row as a parameter?)   The returning value in this case is a collection of Asset objects (I have not defined the Asset class here, I just provided the snippet as an example of MS Access interaction).

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                I had missed that :-O . It would require .NET 3.5 and linq to use

                Rows.OfType<T>()

                or similar

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Why are you using VB6? Do you hate yourself? (Christian Graus)

                1 Reply Last reply
                0
                • G gamer1127

                  Can someone give me some books that discusses completely microsoft visual c# 2005 with relational database particularly the ms access database? Because I have a book that has the same discussions but with sql server and with minimal ms access discussion.

                  R Offline
                  R Offline
                  Roger Wright
                  wrote on last edited by
                  #8

                  Your book using SQL Server examples should give you enough to get things working. In the .Net Framework, the System.Data namespace are classes for several types of provider, and the syntax for each is nearly identical. For a connection, SQL Server needs SqlConnection, for MS Access you use OleDbConnection. Similarly, while SQL Server uses SqlCommand, Access uses OleDbCommand. The slight differences, if any, in the arguments each method requires can be resolved with the clues given by IntelliSense, or simply using Help in Visual Studio. Try searching Help for 'System.Data.OleDb' and see what classes are revealed.

                  "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                  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