###前提・実現したいこと
ここに質問したいことを詳細に書いてください
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
###発生している問題・エラーメッセージ
エラーメッセージ ```型 'System.Data.OleDb.OleDbException' のハンドルされていない例外が System.Data.dll で発生しました ###該当のソースコード ```ここに言語を入力 ここにご自身が実行したソースコードを書いてください
using System;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Text.RegularExpressions;
namespace DBselect_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); OleDbCommand command = new OleDbCommand(); int ID; string Name; DateTime Birth; conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db\Db2.mdb"; conn.Open(); string iID = textBox2.Text; string iName = textBox3.Text; string iBirth = textBox4.Text; int flg = 0; string sql = "SELECT * FROM t_member WHERE"; if (iID != "") { sql += " ID = @ID"; OleDbParameter pID = new OleDbParameter("@ID", iID); command.Parameters.Add(pID); flg = 1; } if (iName != "") { if (flg != 0) { sql += " and "; } sql += " m_name like @NAME "; string eName = escapeString(iName); OleDbParameter pName = new OleDbParameter("@NAME", eName); command.Parameters.Add(pName); flg = 1; } if (iBirth != "") { if (flg != 0) { sql += " and "; } sql += " m_birth = @BIRTH "; OleDbParameter pBirth = new OleDbParameter("@BIRTH", iBirth); command.Parameters.Add(pBirth); flg = 1; } if (flg == 0) { return; } command.CommandText = sql; command.Connection = conn; OleDbDataReader reader = command.ExecuteReader(); memberDataSet.Clear(); while (reader.Read()) { ID = reader.GetInt32(0); Name = reader.GetString(1); Birth = reader.GetDateTime(2); Console.WriteLine("ID:" + iID + "名前:" + iName + "生年月日:" + iBirth); } conn.Close(); } private string escapeString(string iName) { string str = "%" + Regex.Replace(iName, "[_%\\[#]", "#$0") + "%"; return str; } private void button1_Click(object sender, EventArgs e) { } }
}
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報