好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#连接Access和SQLServer数据库

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Data.OleDb;using System.Windows.Forms;using System.Data.SqlClient;namespace S

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Data.OleDb; using System.Windows.Forms; using System.Data.SqlClient; namespace Str { public partial class Form1 : Form { public Form1() { InitializeComponent(); /* * connect to Sql Server */ string strConnection = "Data Source=ZRQ-PC;"; strConnection+="Initial Catalog=master;Integrated Security=True"; SqlConnection objConnection = new SqlConnection(strConnection); objConnection.Open(); objConnection.Close(); /**************************************************************/ /* * connect to access table */ //string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;"; //strConnection += @"Data Source=C:/Users/ZRQ/Documents/STU.accdb"; //OleDbConnection objConnection = new OleDbConnection(strConnection); //objConnection.Open(); //objConnection.Close(); /**************************************************************/ /* *as for connect to Oracle or MySql 等我学了再说吧……(*^__^*) */ } } }

其中的简易办法:

在[服务器资源管理器]中选择要连接的数据,then看它的属性中Name,copy to strConnection 即可~

查看更多关于C#连接Access和SQLServer数据库的详细内容...

  阅读:41次