In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to operate Access in C# to read mdb by column. I hope you will get something after reading this article. Let's discuss it together.
ADO.NET in C # cannot programmatically create a completely new ACCESS (MDB) database, so it can only be operated using ADOX, a link library from COM.
The main knowledge points of Access operation in C # are as follows:
Using System.Data.OleDb; using System.Data
C # operates the Access connection string:
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=product.mdb"
C # operate Access to establish a connection:
OleDbConnection connection = new OleDbConnection (connectionString)
The C # operation Access uses the OleDbCommand class to execute the Sql statement:
OleDbCommand cmd = new OleDbCommand (sql, connection); connection.Open (); cmd.ExecuteNonQuery ()
An example of reading mdb content by column in C# operation Access is as follows:
The columns array stores the name of the column you want to query (you must make sure that the column you want exists in the mdb table)
/ / read mdb data public static DataTable ReadDataByColumns (string mdbPaht,string tableName, string [] columns, ref bool success) {DataTable dt = new DataTable (); try {DataRow dr; / / 1, read mdb string strConn = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath + "; Jet OLEDB:Database Password=haoren"; OleDbConnection odcConnection = new OleDbConnection (strConn) / / 2. Open the connection C# operation Access to read mdb odcConnection.Open () by column; / / establish the SQL query OleDbCommand odCommand = odcConnection.CreateCommand (); / / 3, enter the query statement string strColumn = ""; for (int I = 0; I < columns.Length; iTunes +) {strColumn+ = columns [I] .ToString () + ",";} strColumn = strColumn.TrimEnd (','); odCommand.CommandText = "select" + strColumn+ "from" + tableName / / establish column read mdb OleDbDataReader odrReader for read C# operation Access = odCommand.ExecuteReader (); / / query and display data C# operation Access column read mdb int size = odrReader.FieldCount; for (int I = 0; I < size; iTunes +) {DataColumn dc; dc = new DataColumn (odrReader.GetName (I)); dt.Columns.Add (dc) } while (odrReader.Read ()) {dr = dt.NewRow (); for (int I = 0; I < size; I +) {drr [odrReader.GetName (I)] = odrReader [odrReader.GetName (I)] .ToString ();} dt.Rows.Add (dr);} / close connection C# operation Access read mdb odrReader.Close () by column; odcConnection.Close (); success = true Return dt;} catch {success = false; return dt;}} after reading this article, I believe you have a certain understanding of "how to read mdb by column when operating Access in C#". If you want to know more about it, welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.