本文主要是介绍C#连接ACCESS和SQL2000,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/// 应用程序的主入口点。/// </summary>
[STAThread]
static void Main(string[] args)
{
//以下是连接Access
OleDbConnection dbconn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:/a.mdb");
dbconn.Open();
//OleDbCommand cmd=new OleDbCommand("select * from test1",dbconn);
OleDbCommand cmd=dbconn.CreateCommand();
cmd.CommandText="select * from test1";
cmd.CommandType=CommandType.Text;
OleDbDataReader reader=cmd.ExecuteReader();
//以下是连接SQL2000
/*SqlConnection conn=new SqlConnection("server=localhost;Initial catalog=NorthWind;user ID=sa;password=;");
conn.Open();
SqlCommand cmd=conn.CreateCommand();
cmd.CommandText="select * from Customers";
cmd.CommandType=CommandType.Text;
SqlDataReader reader=cmd.ExecuteReader(CommandBehavior.CloseConnection);*/
while(reader.Read())
{
output=string.Format("custormer {0}:{1} works for {2}",reader.GetString(1),reader.GetString(2),reader.GetString(3));
Console.WriteLine(output);
}
}
}
}
这篇关于C#连接ACCESS和SQL2000的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!