private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (this.dataGridView1.Rows.Count == 0) { return; } if (e.RowIndex < 0) { return; } DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; if (e.ColumnIndex == 4) { //表示用户点击了修改按钮 course c = (course)row.DataBoundItem; sc s_c = new sc(); //s_c.sno = common.Name; s_c.sno = common.Name; s_c.cno = c.cno; s_c.grade = 0; if (sc.Insertsc(s_c) == 1) { MessageBox.Show("insert success"); } } }
public static int Insertsc(sc s_c) { int result = 0; string sql = "insert into sc(sno,cno,grade) values(:sno,:cno,:grade)"; OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno", OracleDbType.Char, 10), new OracleParameter(":cno", OracleDbType.Char, 4), new OracleParameter(":grade", OracleDbType.Int32) }; para[0].Value = s_c.sno; para[1].Value = s_c.cno; para[2].Value = s_c.grade; OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["strCon"].ConnectionString); try { con.Open(); OracleCommand cmd = new OracleCommand(sql, con); cmd.Parameters.AddRange(para); result = cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(result); }
private void button1_Click(object sender, EventArgs e) { sc s_c = new sc(); s_c.sno = tbsno.Text; s_c.cno = tbcno.Text; s_c.grade = Convert.ToInt32(tbgrade.Text); //把课程c放入数据库 if (sc.Insertsc(s_c) == 1) { MessageBox.Show("insert success"); } }
private void button1_Click(object sender, EventArgs e) { sc s_c = new sc(); s_c.sno = tbsno.Text;//保持不变的 s_c.cno = tbcno.Text; s_c.grade = Convert.ToInt32(tbgrade.Text); if (sc.Updatesc(s_c) == 1) { MessageBox.Show("update success"); } else { MessageBox.Show("可能没有找到记录"); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (this.dataGridView1.Rows.Count == 0) { return; } if (e.RowIndex < 0) { return; } DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; if (e.ColumnIndex == 3) { //表示用户点击了删除按钮 string sno = row.Cells[0].Value.ToString(); string cno = row.Cells[1].Value.ToString(); if (sc.Deletesc(sno, cno) == 1) { MessageBox.Show("delete success"); //this.dataGridView1.Rows.Remove(row);//出问题 } else { MessageBox.Show("没有找到数据"); } } else if (e.ColumnIndex == 4) { //表示用户点击了修改按钮 sc s_c = (sc)row.DataBoundItem; Form_scUpdate2 frm = new Form_scUpdate2(); frm.tbsno.Text = s_c.sno; frm.tbcno.Text = s_c.cno; frm.tbgrade.Text = s_c.grade.ToString(); frm.ShowDialog(); } }
public static List <sc> Selectsc(string sno) { string sql = "select sc.sno,cno,grade from sc,student where student.sno=sc.sno and student.sno like :sno"; OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno", OracleDbType.Char, 10) }; para[0].Value = sno + "%"; List <sc> list = new List <sc>(); //创建链接,打开连接,创建命令对象,执行命令,关闭连接 OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["strCon"].ConnectionString); try { con.Open(); OracleCommand cmd = new OracleCommand(sql, con); cmd.Parameters.AddRange(para); OracleDataReader odr = cmd.ExecuteReader(); while (odr.Read()) { sc s_c = new sc(); //c.Cno = odr.GetString(0); //ord["cno']. s_c.sno = odr["sno"].ToString(); s_c.cno = odr.GetString(1); //c.Cpno = odr.GetString(2); s_c.grade = odr.GetInt32(2); list.Add(s_c); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(list); }