| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2252 人关注过本帖
标题:datagridviewg更新记录出错
取消只看楼主 加入收藏
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
收藏
 问题点数:0 回复次数:0 
datagridviewg更新记录出错
private void button1_Click_1(object sender, EventArgs e)
        {
            string sql = "update text1 set bh='" + textBox1.Text + "'mc='" + textBox2.Text + "'bz='" + textBox3.Text + "'where bh=this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()";
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=LUKE\\SQLEXPRESS;uid=sa;pwd=sa;database=luke";
            conn.Open();
            DataTable dt = new DataTable("resouce");
            dt.Clear();
            SqlCommand command = new SqlCommand(sql, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = command;
            ad.Fill(dt);
            dt.Clear();
            MessageBox.Show("该学生已被删除!", "提示");
            SqlDataAdapter adp = new SqlDataAdapter("select * from text1", conn);
            adp.Fill(dt);
            dataGridView1.DataSource = dt.DefaultView;

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dataGridView1.ReadOnly = true;
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=LUKE\\SQLEXPRESS;uid=sa;pwd=sa;database=luke";
            conn.Open();
            DataTable dt = new DataTable("resouce");
            dt.Clear();
            SqlDataAdapter adp = new SqlDataAdapter("select * from text1", conn);
            adp.Fill(dt);
            dataGridView1.DataSource = dt.DefaultView;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count > 0)
                textBox1.Text = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                textBox2.Text = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                textBox3.Text = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
        }

图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: database private server update where 
2016-08-31 14:55
快速回复:datagridviewg更新记录出错
数据加载中...
 
   



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

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