1. Install and register the DB2 dot NET Data provider driver on the machine where the dot NET Framework is already installed
2. Then introduce the Uing System.Data.Common assembly to the DOT NET Framework's namespaces
3. Start the database operation
DbProviderFactory factory = Dbproviderfactories.getfactory ("IBM.") Data.db2 ");
DbConnection con = factory. CreateConnection ();
Dbconnectionstringbuilder SB = Factory. Createconnectionstringbuilder ();
Sb. ConnectionString = "UID=ZHANGKB;PWD=ANDY,./8; Server=192.168.0.11:50000;database=issue ";
Con. ConnectionString =SB. ConnectionString;
Con. Open ();
DbCommand DBC = con. CreateCommand ();
Dbc.commandtext = "Select Bank_name from ISSUE. S_bank WHERE bank_no= ' 1101 ';
string s = dbc. ExecuteScalar (). ToString ();
Con. Close ();
Response.Write (s);
Note: Here is an explanation of the above code:
DbProviderFactory The purpose of this sentence is to declare that my next operation is based on IBM.DATA.DB2
The key word is the connection string of the database: SB. Connetiongstring= "UID=ZHANGKB;PWD=ANDY,./8; Server=192.168.0.11:50000;database=issue ";
UID is the user name of the DB2 database, PWD is the password corresponding to the DB2 database username, the server is to specify the IP address of the DB2 database you want to connect to and the corresponding port number, and the port number of the DB2 database under Windows is generally 50000. In other cases, such as Unix,linux, the 60000.database is the name of the database you are saying you want to access. The rest of the operation of their own look at the understanding.