| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2270 人关注过本帖
标题:datagridviewg更新记录出错
只看楼主 加入收藏
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
收藏
 问题点数:0 回复次数:2 
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
沉迷敲代码
Rank: 1
等 级:新手上路
帖 子:11
专家分:2
注 册:2016-8-31
收藏
得分:0 
回复 楼主 lukebc
第3行ma没有,号
2016-08-31 20:27
沉迷敲代码
Rank: 1
等 级:新手上路
帖 子:11
专家分:2
注 册:2016-8-31
收藏
得分:0 
string sql = "update text1 set bh='" + textBox1.Text + "',mc='" + textBox2.Text + "',bz='" + textBox3.Text + "'  where bh=this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()";
改的时候每个要,号分开   where条件前加空格
2016-09-01 11:13
快速回复:datagridviewg更新记录出错
数据加载中...
 
   



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

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