初めて AS400 システムに接続しようとしましたが、どこかで失敗しています。以下は、いくつかのサンプル アプリケーションに基づいてまとめた現在のコードです。現在、私のコードはrecordList.Open()
次のメッセージで失敗しています:
Execption Source: Microsoft OLE DB Provider for ODBC Drivers
Message: ODBC driver does not suppor tthe requested properties.
Data: System.Collections.ListDIctionaryInternal
AS400 にクエリを実行し、その結果を使用して Windows フォーム ListView コントロールに入力しようとしています。明らかに私は見落としているか、何か間違ったことをしています。私が台無しにしているこの種のスポットで誰かがもっと経験できますか?
コード:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Odbc;
namespace MemberRecordChange
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
this.dtpDate.Value = DateTime.Now;
cmbLetterType.Items.Add("Address Change (old address)(Active/Inactive member)");
cmbLetterType.Items.Add("Address Change (old address)(Benefit Recipeint)");
cmbLetterType.Items.Add("Address Change (new address)(Active/Inactive member)");
cmbLetterType.Items.Add("Address Change (new address)(Benefit Recipeint)");
cmbLetterType.Items.Add("Name Change Letter");
cmbLetterType.Items.Add("Welcome Letter");
cmbLetterType.Items.Add("Nomination of Beneficiary Form");
//~~~~~~~~~~~~This is for debugging purposes. I have other code between this step and the function being called below, but first I need to fill the ListView control~~~~~~~~~~~~~~~~~~~~~~~~~~~
GetiSeriesData("test", "test", "MY-FULL-QUERY");
}
private void btnMerge_Click(object sender, EventArgs e)
{
.......
}
public void GetiSeriesData(string docLoc, string docSource, string query)
{
DataTable addresses = new DataTable();
DataTable changes = new DataTable();
string connString = string.Format("DRIVER=Client Access ODBC Driver (32-bit); SYSTEM=XX.XX.X.XX; UID=XXXXX; PWD=XXXXX");
ADODB.Connection conn = new ADODB.Connection();
ADODB.Recordset recordList = new ADODB.Recordset();
OdbcDataAdapter da = new OdbcDataAdapter();
ADODB.Command cmd = new ADODB.Command();
string memName = "";
string startTime = this.dtpDate.Value.ToString("yyyy-MM-dd") + "-00.00.00.000000";
string endTime = this.dtpDate.Value.ToString("yyyy-MM-dd") + "-23.59.00.000000";
try
{
conn.Open(connString, null, null, 0);
//????
cmd.ActiveConnection = conn;
cmd.CommandText = query;
//addresses.Clear();
//da.Fill(addresses);
// EXCEPTION THROWN ON BELOW LINE
recordList.Open(query, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 1);
// CODE EXECUTION DOES NOT REACH THE BELOW
if (!recordList.EOF)
{
memName = recordList.Fields["NAME"].Value.ToString();
lvData.View = View.Details;
Int16 x = 0;
while (!recordList.EOF)
{
lvData.Items.Add(recordList.Fields["MEMNO"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["NAME"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["ADDR1"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["ADDR2"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["CITY"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["STATE"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["ZIP"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["OLD_ADDR1"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["OLD_ADDR2"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["OLD_CITY"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["OLD_STATE"].Value.ToString().Trim());
lvData.Items[x].SubItems.Add(recordList.Fields["OLD_ZIP"].Value.ToString().Trim());
x += 1;
recordList.MoveNext();
}
}
else
{
MessageBox.Show("No records found");
}
}
catch (Exception ex)
{
MessageBox.Show("Source:\t" + ex.Source + "\nMessage: \t" + ex.Message + "\nData:\t" + ex.Data);
}
finally
{
recordList.Close();
conn.Close();
}
}
}
}
編集:
その一部を理解しましたが、.SubItems をまだコントロールに表示していません。
string connString = "DRIVER=Client Access ODBC Driver (32-bit); SYSTEM=XX.XX.X.XX; UID=XXXX; PWD=XXXX";
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = connString;
OdbcCommand cmd = new OdbcCommand(query, conn);
conn.Open();
OdbcDataReader dr = cmd.ExecuteReader();
if (!dr.HasRows)
{
throw new Exception("No records found.");
}
Int16 x = 0;
while (dr.Read())
{
lvData.Items.Add(dr["memno"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["NAME"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["ADDR1"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["ADDR2"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["CITY"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["STATE"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["ZIP"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["OLD_ADDR1"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["OLD_ADDR2"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["OLD_CITY"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["OLD_STATE"].ToString().Trim());
lvData.Items[x].SubItems.Add(dr["OLD_ZIP"].ToString().Trim());
x += 1;
}