// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Y)) { c1.charactorName = "change"; dbUtil.Update(c1); dbUtil.CloseConnection(); SqliteDataReader reader = dbUtil.ReadFullTable <TestCharactor>(); while (reader.Read()) { Debug.Log(reader.GetString(reader.GetOrdinal("charactorID"))); Debug.Log(reader.GetString(reader.GetOrdinal("charactorName"))); } } }
private void DeleteStu() { //判断是否选中数据 if (this.dataGridView1.CurrentRow != null) { //提示是否删除 DialogResult dr = MessageBox.Show("确定要删除学号为 " + dataGridView1.CurrentRow.Cells[0].Value + " 的学生信息吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); //如果选中是 则删除 if (dr == DialogResult.Yes) { try { string sql = string.Format("delete from t_students where sid={0}", dataGridView1.CurrentRow.Cells[0].Value); MySqlCommand cmd = new MySqlCommand(sql, dbUtil.Connection); dbUtil.OpenConnection(); int result = cmd.ExecuteNonQuery(); if (result == 1) { MessageBox.Show("删除成功", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //删除成功重新加载数据 this.SetDataStaff(); } else { MessageBox.Show("删除失败", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("数据库操作错误", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { dbUtil.CloseConnection(); } } } }