コード例 #1
0
ファイル: Form1.cs プロジェクト: xingheng/SQLite_CSharp
        private void btnRefreshAll_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();

            DataTable dt = null;

            dt = (DataTable)DBOperation.SQLiteRequest_Read("SELECT * FROM " + strTableName);
            foreach (DataRow row in dt.Rows)
            {
                int      count    = row.ItemArray.Length;
                string[] cellList = new string[count];
                for (int i = 0; i < count; i++)
                {
                    cellList[i] = row.ItemArray[i].ToString();
                }

                ListViewItem viewItem = new ListViewItem(cellList);
                listView1.Items.Add(viewItem);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: xingheng/SQLite_CSharp
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count <= 0)
            {
                SetCurrentPerson(null);
                MessageBox.Show("You should select a item in list view at first.", "Delete a row");
                return;
            }

            Person p       = GetCurrentPerson();
            string cmdText = "DELETE FROM " + strTableName +
                             " WHERE id=@id";
            Exception ret = DBOperation.SQLiteRequest_Write(cmdText,
                                                            "@id", p.Id);

            if (ret != null)
            {
                MessageBox.Show("Failed!\r\nret: " + ret.ToString() + "cmdText: " + cmdText, "Delete a row");
            }
            btnRefreshAll_Click(sender, e);
        }