| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1134 人关注过本帖
标题:请求指教
只看楼主 加入收藏
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
结帖率:76.92%
收藏
 问题点数:0 回复次数:8 
请求指教
各位大哥帮我看看.我刚学这门语言.不知道错在那里,这个实现收入,支出的添加和删除.收入,支出的各种查询.添加是可以了.查询的我//了后可模糊查询.去掉后就出错.删除也出错.删除是我选中后就删除.
    交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。

无情 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("删除成功!");
搜索更多相关主题的帖子: 收入 sql 指教 请求 sender 
2008-07-22 20:32
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
得分:0 
你要哪种删呢?是选中删还是打上前面的勾删.
string id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
你这里什么也没指定就给他全删了

菜猪猪``
2008-07-22 20:51
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
得分:0 
int IsCheck = 0;
            int rows = this.dgvView.Rows.Count;
            for (int j = 0; j < this.dgvView.Rows.Count; j++)
            {
                if (Convert.ToBoolean(this.dgvView.Rows[j].Cells[0].EditedFormattedValue))
                {
                    IsCheck++;
                }
            }
            if (IsCheck == 0)
            {
                MessageBox.Show("没有选择一个项!");
                return;
            }
            if (MessageBox.Show("确实删除" + IsCheck + "项?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
            {
                return;
            }
            for (int i = rows - 1; i >= 0; i--)
            {
                if (Convert.ToBoolean(this.dgvView.Rows[i].Cells[0].EditedFormattedValue.ToString()))
                {
                    string UserName = this.dgvView.Rows[i].Cells[1].Value.ToString();
                    string StrQuary = "delete from t_xinxi where UserName = '" + UserName + "'";
                    this.dgvView.Rows.RemoveAt(i);
                    SqlConnection myConnection = new SqlConnection(StrConn);
                    myConnection.Open();
                    SqlCommand myCommand = new SqlCommand(StrQuary, myConnection);
                    myCommand.ExecuteNonQuery();
                    myConnection.Close();
                }
            }
            MessageBox.Show("删除成功!");



这是我的方法还有gridview里的ColoumType是DataGridViewCheckBoxColumn

菜猪猪``
2008-07-22 20:53
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
回复 2# xyq701830 的帖子
我是选中后就全部删除的啊.
2008-07-24 16:24
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
回复 3# xyq701830 的帖子
恩.我书上也是你这种方法.但是我觉得我的这种比较简单.只要选择要删除的在点击删除按钮就好了.现在我的删除已经好了.就是查看还有错误.能不能帮我看看错在那.
2008-07-24 16:31
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
我的删除已经知道错在那了.SqlCommand co = new SqlCommand(sql, cn);这里错了.现在我的查看语句还有问题.错误我找不出来.谁能帮我看看.
2008-07-24 16:34
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
得分:0 
代码发出来啊``

菜猪猪``
2008-07-24 16:38
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
得分:0 
SqlConnection coon = new SqlConnection("server=.;uid=sa;pwd=;database=家庭收入支出管理系统");
            SqlDataAdapter sda = new SqlDataAdapter(sql, coon);
            DataSet ds = new DataSet();

SqlDataAdapter sda = new SqlDataAdapter(sql, coon);
 能这样吗?sql, coon有这样 ?

菜猪猪``
2008-07-24 16:41
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
可以的啊.这样的没问题啊.
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];
2008-07-28 18:54
快速回复:请求指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017230 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved