使用
IBM DB2 UDB for iSeries .NET Provider
连接i5数据库进行编程
1. 安装 .NET Framework (Microsoft 提供,redbooks 建议使用 .net 1.1)
2. 安装CLIENT ACCESS中的.net data provider(IBM 提供)
3. 配置 .Net 1.1 (重要)
l 安装.NET Framework
到 www.msdn.com 下载.NET Framework ,
下载地址:
http://www.microsoft.com/downloads/details.aspx?familyid=9B3A2CA6-3647-4070-9F41-A333C6B9181D&displaylang=en
先到微软网站下载.net Framework 安装,然后再安装client access 中的.net data provider .
l 安装CLIENT ACCESS中的.net data provider(IBM 提供)
使用 Client access 中的选择性安装,挑选 Data Access 部分,选择 .NET Data Provider 进行安装。
l 配置 .Net 1.1 (重要)
步骤如下,配置之后,在microsoft studio 中可以看到此refence.
在microsoft studio 中可以看到以下Reference:
详细情况如下:
配置完成之后,在microsoft studio 中可以使用IBM .net data for iSeries 进行编程了。下面举两个例子。一个是C#的,一个是VB.net 的。
l C#例子
创建控制台应用,
程序如下:
using System;
using System.Collections.Generic;
using System.Text;
using IBM.Data.DB2.iSeries;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
iDB2Connection cn = new iDB2Connection("DataSource=myiSeries;");
cn.Open();
Console.WriteLine(cn.JobName);
cn.Close();
}
}
}
做以下操作
1.在 Visual Studio .NET 中, 选择save all
2.选择Build菜单中的 → Rebuild solution.
3.光标移动到cn.Close() 行处,选择 run to cursor 功能菜单。
将打开一个iSeries 的登陆界面
首先要在windows host 表里添加myiseries 的ip 地址
就可以进行连接了。结果如下
l VB.net 例子
Imports IBM.Data.DB2.iSeries
Module Module1
Sub Main()
'create table mylib.mytable (col1 int, col2 char(20))
Dim cn As New iDB2Connection("DataSource=myiSeries;")
'We are purposely creating a command that will fail because the values we're trying
'to insert don't match the column types of the table.
Dim cmd As New iDB2Command("insert into mylib.mytable values('some string', 1)")
cmd.Connection = cn
cn.Open()
'Execute the command. This should fail and we will get into the Catch block
Try
cmd.ExecuteNonQuery()
Catch e As iDB2Exception
'Examine the exception and print out various properties
Console.WriteLine("Exception: ")
Console.WriteLine("Source: " & e.Source)
Console.WriteLine("Message: " & e.Message)
Console.WriteLine("MessageDetails: " & e.MessageDetails)
Console.WriteLine("MessageCode: " & e.MessageCode)
Console.WriteLine("SqlState: " & e.SqlState)
Console.WriteLine("iDB2Exception type: " & e.GetType().ToString())
Console.WriteLine("There are {0} errors in the error collection.", e.Errors.Count)
End Try
cn.Close()
End Sub
End Module
首先要创建mylib .mytable 等库和表,然后看结果如下
说明插入成功。
我自己琢磨出来了,基本上可以进行开发了。
要word文档,可以发邮件给。
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/1778601/viewspace-898846/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/1778601/viewspace-898846/