记录不会在C Sharp中更新 [英] Records are not updated in c sharp

查看:77
本文介绍了记录不会在C Sharp中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么记录不通过下面给出的代码进行更新?没有任何错误,异常也给出了消息,还显示记录已更新,但是当我在表中看到记录未更新时为什么?请帮帮我.

Why records is not updating by the code given below ? No any error and exceptions are giving message also shown record updated but when i see in table the records are not updated why ?Please help me.

private void button3_Click(object sender, EventArgs e)
        {
            string sa = textBox1.Text.Trim();
            try
            {
                string connetionString = null;
                connetionString = "Data Source=JDPANDEY-PC;Initial Catalog=amsco;User ID = sa;Password= 123";
                cnn = new SqlConnection(connetionString);

                cnn.Open();

                ds = new DataSet();
                string sql = "select * from employee";
                da = new SqlDataAdapter(sql, cnn);
                da.Fill(ds, "employee");
                int r = 0;
                DataRow[] rs;
                rs = ds.Tables["employee"].Select("eid='" + textBox1.Text.Trim() + "'");
                r = rs.Length;
                if (r > 0)
                {
                    string str = "UPDATE employee set ename='" + textBox2.Text.Trim() + "',fname='" + textBox3.Text.Trim() + "' WHERE  eid ='" + textBox1.Text.Trim() + "'";
                    cmd = new SqlCommand(str, cnn);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Record UPDATED");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cnn.Close();

        }

推荐答案

此代码在我端正常运行.更新记录后,刷新数据库表..
This code is working fine at my end.After updating the record refresh your database table..


这篇关于记录不会在C Sharp中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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