This article describes the method of using ODBC to connect to databases in C#. Share it for your reference, as follows:
using System; using ; using ; using ; using ; namespace ODBCtest { class Program { static void Main(string[] args) { //ODBC connection string conString = "DSN=tian"; //tian represents the user data source name of ODBC string sql = "select count(*) from stuinfo"; //stuinfo is a table in the database bound to the user's data source OdbcConnection con = new OdbcConnection(conString); (); OdbcCommand com = new OdbcCommand(sql, con); int i = Convert.ToInt32(()); (i); //OLEDB connection string conString = @"Provider=.4.0;Data Source=D:\"; //Connect the Access database string sql = "select count(*) from stuinfo"; OleDbConnection con = new OleDbConnection(conString); (); OleDbCommand com = new OleDbCommand(sql, con); int i = Convert.ToInt32(()); (i); } } }
For more information about C# related content, please check out the topic of this site:Summary of thread usage techniques for C# programming》、《Summary of C# operation skills》、《Summary of XML file operation skills in C#》、《Tutorial on the usage of common C# controls》、《Summary of WinForm control usage》、《C# data structure and algorithm tutorial》、《Summary of C# array operation skills"and"Introduction to C# object-oriented programming tutorial》
I hope this article will be helpful to everyone's C# programming.