为何这样连接数据库不行啊?
我刚开始搞数据库请大家指教,为何这样连接数据库不行啊?没有反应,什么显示都没有啊?
using System;
using System.Data;
using System.Data.OleDb;
namespace oledb
{
class oledbprovider
{
static void Main()
{
string constr=@"server=(local)\NetSDK;provider=SQLOLEDB;"+"Integrated Security=SSPI;database=Northwind";
OleDbConnection oledbconn=new OleDbConnection(constr);
try
{
oledbconn.Open();
string sql="SELECT * FROM Employees";
OleDbCommand oledbcomm=new OleDbCommand(sql,oledbconn);
OleDbDataReader oledbdatareader=oledbcomm.ExecuteReader();
Console.WriteLine("this program demonstrtes the use of"+"oledb.net data provider");
Console.WriteLine("FirstName\tLastName\n");
while(oledbdatareader.Read())
{
Console.WriteLine("{0}|{1}",oledbdatareader["FirstName"].ToString().PadLeft(10),oledbdatareader["LaseName"].ToString().PadLeft(10));
}
}
catch(Exception ex)
{
Console.WriteLine("ERROR:"+ex.Message);
}
finally
{
oledbconn.Close();
Console.ReadLine();
}
}
}
}