资源介绍
private void button3_Click(object sender, EventArgs e)
{
string number = textBox2.Text;
string bookname = textBox3.Text;
string press = textBox4.Text;
string name = textBox6.Text;
string price = textBox5.Text;
DateTime dt= dateTimePicker1.Value;
string bookid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
MessageBox.Show(bookid);
string sql1 = "update book set number='{0}',bookname ='{1}',press='{2}',price='{3}',dt='{4}'where bookid ='{5}' ";
sql1 = string.Format(sql1,number, bookname,press,price,dt,bookid);
string sql2 = "update categorybook set name='{0}'where categoryid in(select categoryid from book where bookid='{1}')";
sql2 = string.Format(sql2, name, bookid);
SqlConnection conn = new SqlConnection();
conn.ConnectionString="server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true";
//conn.ConnectionString = "server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0";
conn.Open();
SqlTransaction st = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
try
{
cmd.CommandText = sql1;
cmd.ExecuteNonQuery();
cmd.CommandText = sql2;
cmd.ExecuteNonQuery();
st.Commit();
Showmsg();
MessageBox.Show("修改成功");
}
catch
{
MessageBox.Show("修改失败");
}
}
private void button9_Click(object sender, EventArgs e)
{
if (dataGridView1.RowCount > 0)
{
dataGridView1.SelectAll();
}
}
private void button10_Click(object sender, EventArgs e)
{
while(dataGridView1.SelectedRows.Count > 0)
{
DataGridViewRow dv = dataGridView1.SelectedRows[0];
dv.Selected = false;
}
}
private void button11_Click(object sender, EventArgs e)
{
string sql = "select * from book ";
SqlConnection conn = new SqlConnection("server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true");
//SqlConnection conn = new SqlConnection("server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0");
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
ListViewItem lvi = new ListViewItem();
lvi.Text = sdr["number"].ToString();
lvi.SubItems.Add(sdr["bookname"].ToString());
lvi.SubItems.Add(sdr["price"].ToString());
listView1.Items.Add(lvi);
}
sdr.Close();
conn.Close();
}