请求指教
各位大哥帮我看看.我刚学这门语言.不知道错在那里,这个实现收入,支出的添加和删除.收入,支出的各种查询.添加是可以了.查询的我//了后可模糊查询.去掉后就出错.删除也出错.删除是我选中后就删除.交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。
无情 20:21:35
private void button4_Click(object sender, EventArgs e)
{
string sql = "select * from 家庭收入表";// where ";
//if (comboBox7.Text != "")
// sql += "收入类型='" + comboBox7.Text + "'and";
//if (comboBox8.Text != "")
// sql += "收入金额='" + comboBox8.Text + "'and ";
//sql += "收入时间 >= '" + dateTimePicker4.Value.ToShortDateString() + "' and 收入时间< = '" + dateTimePicker5.Value.ToShortDateString() + "'";
//if (comboBox12.Text != "")
//sql += "收入人= '" + comboBox12.Text +"'and";
//执行select 语句
SqlConnection coon = new SqlConnection("server=.;uid=sa;pwd=;database=家庭收入支出管理系统");
SqlDataAdapter sda = new SqlDataAdapter(sql, coon);
DataSet ds = new DataSet();
sda.Fill(ds);
//显示
dataGridView1.DataSource = ds.Tables[0];
}
private void button5_Click_1(object sender, EventArgs e)
{
string sql = "select * from 家庭支出表";// where ";
//if (comboBox10.Text != "")
// sql += "支出类型 = '" + comboBox10.Text + "'and";
//if (comboBox9.Text != "")
// sql += "支出金额='" + comboBox9.Text + "'and ";
//sql += "支出时间 >= '" + dateTimePicker7.Value.ToShortDateString() + "' and 支出时间< = '" + dateTimePicker6.Value.ToShortDateString() + "'";
//if (comboBox11.Text != "")
//sql += "支出人= '" + comboBox11.Text +"'and";
//执行select 语句
SqlConnection coon = new SqlConnection("server=.;uid=sa;pwd=;database=家庭收入支出管理系统");
SqlDataAdapter sda = new SqlDataAdapter(sql, coon);
DataSet ds = new DataSet();
sda.Fill(ds);
//显示
dataGridView1.DataSource = ds.Tables[0];
}
private void button6_Click(object sender, EventArgs e)
{
string id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
string sql = "delete from 家庭收入表 where id=" + id ;
SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=家庭收入支出管理系统");
SqlCommand co = new SqlCommand(id , cn);
co.Connection.Open();
co.ExecuteNonQuery();
co.Connection.Close();
MessageBox.Show("删除成功!");
}
private void button7_Click(object sender, EventArgs e)
{
string id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
string sql = "delete from 家庭支出表 where id=" + id;
SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=家庭收入支出管理系统");
SqlCommand co = new SqlCommand(id, cn);
co.Connection.Open();
co.ExecuteNonQuery();
co.Connection.Close();
MessageBox.Show("删除成功!");