C # Connect Access and SQL2000

xiaoxiao2021-03-30  213

Using system; use system.data.sqlclient; using system.data.oledb; Namespace consoleApplication1 {///

/// Class1 summary. /// class class1 {/// /// The primary entry point of the application. /// [stathread] static void main (String [] args) {

// The following is Connecting 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 ();

/ / The following is Connecting 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; sqldataareader 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);}}}}

转载请注明原文地址:https://www.9cbs.com/read-130584.html

New Post(0)