C# books
-
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.
-
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.
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; }
-
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; }
-
if I buy a book about sql server, will i be able to use the sql queries presented in that book to ms access?
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; }
-
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; }
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 listsList<T>
which should be used instead. Also, your final foreach loop may possibly be removed by the use of theAddRange
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) -
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 listsList<T>
which should be used instead. Also, your final foreach loop may possibly be removed by the use of theAddRange
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)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).
-
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).
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) -
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.
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"