Introduction:
In this article,i am going to explain about the ADO.NET common functionalities with DB2 database.
Main:
First for accessing DB2 using asp.net,we need db2 provider.We can download the db2 provider in
IBM web site.
For download:http://www-01.ibm.com/software/data/db2/ad/dotnet.html
Once installed,please use the below namespace,
using IBM.Data.DB2.iSeries;
using IBM.Data.DB2.iSeries; |
Sample Code,
string conStr = "DataSource=local;UserID=USER;Password=PASS; DataCompression=True;";
iDB2Connection cn = new iDB2Connection(conStr);
cn.Open();
iDB2Command cmd = cn.CreateCommand();
cmd.CommandText = "SELECT * FROM EMP WHERE EMPID = @EmpId AND SALARY = @salary";
iDB2DataAdapter da = new iDB2DataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
string conStr = "DataSource=local;UserID=USER;Password=PASS; DataCompression=True;"; iDB2Connection cn = new iDB2Connection(conStr); cn.Open(); iDB2Command cmd = cn.CreateCommand(); cmd.CommandText = "SELECT * FROM EMP WHERE EMPID = @EmpId AND SALARY = @salary"; iDB2DataAdapter da = new iDB2DataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); |
Conclusion:
Hope this helps,
Happy Coding.