VS2003中链接数据库方法

(1).SQL Server ODBC数据连接方法:

String myConnString1=“driver={sql server}; server=10.144.65.44; database=数据库名; uid=username;pwd=password";

System.Data.Odbc.OdbcConnection myConnection1=new System.Data.Odbc.OdbcConnection (myConnString1);           

myConnection1.Open();

System.Data.Odbc.OdbcDataAdapter  mytest1=new  System.Data.Odbc.OdbcDataAdapter ("select *from final_address",myConnection1);

DataSet ds1=new DataSet ();

mytest1.Fill(ds1,"final_address");

DataGrid1.DataSource=ds1;

DataGrid1.DataBind();           

 

(2).Oracle ODBC数据连接方法:

string myConnString4 = "driver={microsoft odbc for oracle}; server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.65.44)

(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=数据库名)));uid=username;pwd=password ";

System.Data.Odbc.OdbcConnection myConnection4 = new System.Data.Odbc.OdbcConnection(myConnString4);         

myConnection4.Open();

System.Data.Odbc.OdbcDataAdapter mytest4=new  System.Data.Odbc.OdbcDataAdapter("select*from  Razor_final_address",myConnection4);

DataSet ds4=new DataSet ();

mytest4.Fill(ds4,"Razor_final_address");

DataGrid1.DataSource=ds4;

DataGrid1.DataBind();

 

(3).SQL Server OleDb数据连接方法:

string myConnString2="PROVIDER=SQLOLEDB;DATA SOURCE=10.144.65.44;database=数据库名;user id=username;pwd=password ";

System.Data.OleDb.OleDbConnection myConnection2 =new  OleDbConnection (myConnString2);   

myConnection2.Open();

System.Data.OleDb.OleDbDataAdapter mytest2=new  OleDbDataAdapter ("select *from final_address",myConnection2);

DataSet ds2=new DataSet ();

mytest2.Fill(ds2,"final_address");

DataGrid1.DataSource=ds2;

DataGrid1.DataBind();

 

(4).Oracle OleDb数据连接方法:

string myConnString5 = "Provider=msdaora;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.65.44)

(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=数据库名)));user id=username;pwd=password ";

System.Data.OleDb.OleDbConnection myConnection5 = new  OleDbConnection (myConnString5);  

myConnection5.Open();

System.Data.OleDb.OleDbDataAdapter mytest5=new OleDbDataAdapter ("select *from Razor_final_address",myConnection5);

DataSet ds5=new DataSet ();

mytest5.Fill(ds5,"Razor_final_address");

DataGrid1.DataSource=ds5;

DataGrid1.DataBind();

 

(5).SQL Server SqlClient数据连接方法:

string myConnString3="server=10.144.65.44;database=数据库名; user id=username;pwd=password";

System.Data.SqlClient.SqlConnection myConnection3 = new  System.Data.SqlClient.SqlConnection (myConnString3);      

myConnection3.Open();

System.Data.SqlClient.SqlDataAdapter mytest3=new  SqlDataAdapter ("select *from final_address",myConnection3);

DataSet ds3=new DataSet ();

mytest3.Fill(ds3,"final_address");

DataGrid1.DataSource=ds3;

DataGrid1.DataBind();

 

(6).Oracle OracleClient数据连接方法:

String myConnString6 = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.65.44)(PORT=1521))

(CONNECT_DATA=(SERVICE_NAME=数据库名)));user id=Razor;password=RazorServerMachine ";

OracleConnection myConnection6 = new OracleConnection(myConnString6);   

myConnection6.Open();

System.Data.OracleClient.OracleDataAdapter mytest6=new OracleDataAdapter("select *from Razor_final_address",myConnection6);

DataSet ds6=new DataSet ();

mytest6.Fill(ds6,"Razor_final_address");

DataGrid1.DataSource=ds6;

DataGrid1.DataBind();

你可能感兴趣的:(2003)