お世話になります。
ただいま検索画面の、実装をおこなっています。
#region 検索時項目が入っている場合のSQL部分でif文を使い
テキストボックスに条件が入っている場合は、そのSQLを通る条件で実装したのですが
改行を');'で区切るとエラーになってしまいます。
どのように区切ればいいのでしょうか。
パラメーターはどのようにすればSQL側に渡せるのでしょうか・
よろしくお願いします。
C#
( "select" +); ( " 損益.日付||曜日.曜日," +); ( "損益.損益額," +); ( "コメント.コメント" +); ( " from" +); ( " 損益テーブル 損益" +); ( " left join 曜日テーブル 曜日" +); ( " on 曜日.ID = 損益.曜日ID" +); ( " left join コメントテーブル コメント" +); ( " on コメント.日付 = 損益.日付" +); if() ( " where 損益.日付 >= '@'" +); if() ( " and 損益.日付 <= '@'" +); if() ( " and 損益.損益額 >= '@'" +); if() ( " and 損益額 <= '@'",con );
C#
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.SQLite; namespace 基幹システム.株式関係 { public partial class kabu : Form { public kabu() { InitializeComponent(); } private void kabu_Load(object sender, EventArgs e) { //DB接続等 string dbPath = Application.StartupPath + @"\kabukanri.db"; using (SQLiteConnection con = new SQLiteConnection("Data Source=" + dbPath)) { DataTable datatable = new DataTable(); #region 画面ロード時に初期表示するためのSQL SQLiteDataAdapter adapter = new SQLiteDataAdapter ("select " + "損益テーブル.日付 ||(曜日テーブル.曜日) as 日付" + ",損益テーブル.損益額" + ",コメントテーブル.コメント from 損益テーブル left join コメントテーブル on" + " 損益テーブル.日付 = コメントテーブル.日付 left join" + " 曜日テーブル on 損益テーブル.曜日ID = 曜日テーブル.ID; ", con); adapter.Fill(datatable); #endregion this.dataGridView1.DataSource = datatable; //ヘッダーを変更 dataGridView1.Columns[0].HeaderText = "日付"; dataGridView1.Columns[1].HeaderText = "損益額"; dataGridView1.Columns[2].HeaderText = "コメント"; } } //検索ボタンを押下したときの処理 private void btnserch_Click(object sender, EventArgs e) { //string dbpath = Application.StartupPath + @"\kabukanri.db"; //using (SQLiteConnection con = new SQLiteConnection("Data source=" + dbpath)) //{ // con.Open(); // using (SQLiteTransaction trans = con.BeginTransaction()) // { // SQLiteCommand cmd = con.CreateCommand(); // } //} //DB接続等 string dbPath = Application.StartupPath + @"\kabukanri.db"; using (SQLiteConnection con = new SQLiteConnection("Data Source=" + dbPath)) { DataTable datatable = new DataTable(); #region 検索時項目が入っている場合のSQL SQLiteDataAdapter adapter = new SQLiteDataAdapter ("select" +); (" 損益.日付||曜日.曜日," +); ("損益.損益額," +); ("コメント.コメント" +); (" from" +); (" 損益テーブル 損益" +); (" left join 曜日テーブル 曜日" +); (" on 曜日.ID = 損益.曜日ID" +); (" left join コメントテーブル コメント" +); (" on コメント.日付 = 損益.日付" +); (" where 損益.日付 >= '@'" +); (" and 損益.日付 <= '@'" +); (" and 損益.損益額 >= '@'" +); (" and 損益額 <= '@'", con); #endregion adapter.Fill(datatable); this.dataGridView1.DataSource = datatable; } } } }
まだ回答がついていません
会員登録して回答してみよう