コード ```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(); } int id; string name; DateTime birth; int score; private void label1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } private string escapeString(string iName) { string str = "%" + Regex.Replace(iName, "[_%\\[#]", "#$0") + "%"; return str; } private void button1_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); OleDbCommand command = new OleDbCommand(); 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); score = reader.GetInt32(3); Console.WriteLine("ID:" + id + "名前:" + name + "生年月日:" + birth + "最高値" + score); } conn.Close(); } } } ![?](a31c52afde15b16efc9351d9b75ddd0a.png) ※accessのデータと連携させて作成しています。 入力したデータが出力はされますが、まるで囲った部分に表示させたいのですがどうしたらいいでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。