吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3295|回复: 5
收起左侧

[其他转载] c# DataGridView

[复制链接]
mjqt 发表于 2017-4-26 15:00
int  stre = Convert.ToInt32(dateview.SelectedRows[1].Cells[0].Value);
int stre = Convert.ToInt32(dateview.Rows[e.RowIndex].Cells[1].Value.ToString());
大佬们,获取选中的值之后
         string connectionstrng = ConfigurationManager.ConnectionStrings["Student"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionstrng);
            string cmdText = "Update stuinfo SET Id='"+number_text.Text+ "',Name='"+ name_text.Text + "',Math='"+math_text.Text+ "' where Id='"+str+"'";
            if (name_text.Text != null && number_text.Text != null && math_text.Text != null)
            {
                using (SqlCommand cmd = new SqlCommand(cmdText, con))
                {
                    con.Open();
                  
                    if (cmd.ExecuteNonQuery()!=-1)
                    {
                        MessageBox.Show("修改成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("格式错误或信息不全");

                    }
                }
                con.Close();
            }
            else
            {
                MessageBox.Show("格式错误");
               
            }
为什么数据区的之没更改啊?

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

吃泡面的鱼 发表于 2017-4-26 16:09
自己刷一下dateview.DataSource
烯特勒 发表于 2017-4-26 16:53
你这只是代表你数据库里的值改了,但你界面上加载的还是没改之前的数据,你刷新下界面,或在修改成功之后重新查询绑定
longiana 发表于 2017-4-26 18:01
hickey. 发表于 2017-4-26 23:24
正在学习c#,还没学到
 楼主| mjqt 发表于 2017-4-29 08:12
还没绑定dateSorue ,是我的事件写错了,已经弄好呢。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 14:04

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表