首页 > 代码库 > C# 链接Sql和Access数据库语句
C# 链接Sql和Access数据库语句
1、sql数据库:
1.1、链接数据语句:server=localhost;database=Data; uid=sa;pwd=123; 或
Data Source=localhost;DataBase=Data;Uid=sa;Pwd=123;
1.2、代码链接数据库:
SqlConnectionStringBuilder csbuilder = new SqlConnectionStringBuilder();
csbuilder.DataSource = "localhost";//Sql链接实例
csbuilder.InitialCatalog = "Data";//数据库名称
csbuilder.UserID = "sa";//链接数据的用户ID
csbuilder.Password = "123";//用户密码
2、Access链接数:
1.1、链接数据语句:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\News.mdb
1.2、代码链接数据库:
OleDbConnectionStringBuilder oleString = new OleDbConnectionStringBuilder();
oleString.Provider = "Microsoft.Jet.OLEDB.4.0";
oleString.DataSource = "News.mdb";