前提・実現したいこと
コンボボックスで選んだ値をSQLに代入したいんですが
選択したものがSQLiteに保存されていない。
原因や対策を知りたい
発生している問題・エラーメッセージ
該当のソースコード
c#
1namespace system 2{ 3 public partial class Form6 : Form 4 { 5 private string db_file = "sample.sqlite";//使用するデータ 6 7 public Form6() 8 { 9 InitializeComponent(); 10 11 //データベースの接続 12 using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + db_file)) 13 { 14 try 15 { 16 conn.Open(); 17 } 18 catch (Exception exception) 19 { 20 MessageBox.Show(exception.Message, "Connection Message", MessageBoxButtons.OK, MessageBoxIcon.Error); 21 } 22 } 23 24 25 } 26 27 private void button1_Click(object sender, EventArgs e) 28 { 29 Form5 Form5 = new Form5(); 30 Form5.Show(); 31 this.Close(); 32 } 33 34 private void button2_Click(object sender, EventArgs e) 35 { 36 //SQLiteに書き込み 37 SQLiteConnection conn = new SQLiteConnection("Data Source=" + db_file); 38 conn.Open(); 39 try 40 { 41 //カラム名と値" 42 string sql = "insert or replace sam(目標) VALUES('Text')"; 43 44 SQLiteCommand com = new SQLiteCommand(sql, conn); 45 com.ExecuteNonQuery(); 46 } 47 catch (SQLiteException exc) 48 { 49 System.Diagnostics.Debug.WriteLine(exc.Message); 50 } 51 finally 52 { 53 conn.Close(); 54 } 55 56 Form7 Form7 = new Form7(); 57 Form7.Show(); 58 this.Close(); 59 } 60 61 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) 62 { 63 //選択された要素の取得 64 string Text = comboBox2.SelectedText; 65 } 66 67 private void Form6_Load(object sender, EventArgs e) 68 { 69 string[] strData = { "運動", "買い物", "早起き", "掃除" }; 70 71 //コンボボックスにアイテムを追加する 72 comboBox2.Items.AddRange(strData); 73 } 74 } 75} 76
補足情報(FW/ツールのバージョンなど)
・VisualStudio2017
・SQLite
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/20 01:07
2018/11/20 02:58
退会済みユーザー
2018/11/20 12:42
退会済みユーザー
2018/11/20 12:42
2018/11/20 13:20
退会済みユーザー
2018/11/20 13:25
2018/11/20 13:27
退会済みユーザー
2018/11/20 13:54
退会済みユーザー
2018/11/20 15:05
2018/11/21 21:46
退会済みユーザー
2018/11/22 02:14