using system;
using system.data;
using system.data.sqlclient;
using system.data.oledb;
namespace consoleapplication1
{
/// <summary>
/// class1 的摘要说明。
/// </summary>
class class1
{
/// <summary>
/// 应用程序的主入口点。
/// </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);*/
string output;
while(reader.read())
{
output=string.format("custormer {0}:{1} works for {2}",reader.getstring(1),reader.getstring(2),reader.getstring(3));
console.writeline(output);
}
}
}
}
新闻热点
疑难解答