编辑,更新,删除datagridview内的Windows应用程序C# [英] Edit,update,delete inside datagridview ,windows application C#

查看:103
本文介绍了编辑,更新,删除datagridview内的Windows应用程序C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何使用Windows应用程序C#在datagridview控件内进行编辑,更新,删除.
任何帮助将不胜感激...

Hi,

How to edit,update,delete inside the datagridview control using windows application C#..

Any help would be appreciated...

推荐答案

SqlConnection myConnection = new SqlConnection();
//now you can set ConnectionString property for myConnection
myConnection.ConnectionString = ConfigurationSettings.AppSettings["myConnectionString"];
try
{
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if (Convert.ToInt32(dataGridView1.Rows[i].Cells["select"].Value) == 1)
        {
            if (dataGridView1.Rows.Count != null)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to proceed in Updation ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {

                        string aa = dataGridView1.Rows[i].Cells["id"].Value.ToString();
                        string sms_policy = dataGridView1.Rows[i].Cells["smspolicyDataGridViewTextBoxColumn"].Value.ToString();
                        string income = dataGridView1.Rows[i].Cells["incomeDataGridViewTextBoxColumn"].Value.ToString();
                        string ratio = dataGridView1.Rows[i].Cells["ratioDataGridViewTextBoxColumn"].Value.ToString();
                        string payment = dataGridView1.Rows[i].Cells["paymentDataGridViewTextBoxColumn"].Value.ToString();
                        string feature = dataGridView1.Rows[i].Cells["featureDataGridViewTextBoxColumn"].Value.ToString();
                        string description = dataGridView1.Rows[i].Cells["descriptionDataGridViewTextBoxColumn"].Value.ToString();


                        SqlCommand cmd = new SqlCommand();
                        cmd.CommandText = "update sms set  sms_policy='" + sms_policy + "',income='" + income + "',ratio='" + ratio + "',payment='" + payment + "',feature='" + feature + "',description='" + description + "'  where id='" + aa + "'";

                        cmd.Connection = myConnection;
                        myConnection.Open();
                        cmd.ExecuteNonQuery();
                        myConnection.Close();
                        Rebind();
                        MessageBox.Show("Update Record Success Folly");



                    }
                }
            }
        }
    }
}

catch (Exception a)
{
    MessageBox.Show("Server Have Technical problem Try After Some Time ");
}


网络上有大量信息,既涉及如何在生产标准代码中执行此操作,又涉及如何使用内置功能编写玩具代码,如果您正在做一个非常简单的应用程序,则不需要正确编写.你尝试了什么?您正在使用什么数据库?
There''s a ton of info on the web, both for how to do this in production standard code, and how to use the built in functionality to write some toy code if you''re doing a very simple app that doesn''t need to be written properly. What have you tried ? What database are you using ?


这篇关于编辑,更新,删除datagridview内的Windows应用程序C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆