更新数据库记录 [英] update record of database

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

问题描述

嗨每一个

我的更新按钮有问题。

当我更新记录然后记录从数据库中删除而不是更新???

这里是更新代码这里有什么问题请指导我?





提前感谢

hi every one
i have a problem in update button.
when i update the record then record removed from the database instead of update???
here is the code of update what''s wrong here please guide me ?


thanks in advance

protected void btnupdate_Click(object sender, EventArgs e)
{

            SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Final Project\FinalProject\FinalProject\App_Data\Record.mdf;Integrated Security=True;User Instance=True");


            string query="Update student set firstname='"+bolobj.firstname+"',lastname='"+bolobj.lastname+"',faname='"+bolobj.fname+"',fcellno='"+bolobj.fcellno+"',fnic='"+bolobj.fnic+"',homeno='"+bolobj.homeno+"',gender='"+bolobj.gender+"',days='"+bolobj.days+"',month='"+bolobj.month+"',year='"+bolobj.year+"',classname='"+bolobj.classname+"'where StdId='"+txtID.Text+"'";

            SqlCommand com = new SqlCommand(query, con);
            con.Open();
            if (com.ExecuteNonQuery() > 0)

                con.Close();

               {
                bolobj.firstname = txtfirstname.Text;
                bolobj.lastname = txtlastname.Text;
                bolobj.fname = txtfaname.Text;
                bolobj.fcellno = txtfcellno.Text;
                bolobj.homeno = txthome.Text;
                bolobj.fnic = txtfnic.Text;
                bolobj.classname = drpclassno.SelectedItem.Text.ToString();
                bolobj.gender = drpgender.SelectedItem.Text.ToString();
                bolobj.days = drpday.SelectedItem.Text.ToString();
                bolobj.month = drpmonth.SelectedItem.Text.ToString();
                bolobj.year = drpyear.SelectedItem.Text.ToString();

                }
                 Label1.Text = " Update Successfully...";


}

推荐答案

试试这个: -



Try This one :-

protected void Button1_Click(object sender, EventArgs e)
       {
           Con = new SqlConnection("Your Connection String");

           Con.Open();
           Cmd = new SqlCommand("update employee set 
           Emp_Name='"+TextBox1.Text+"' where Emp_ID=5",Con);
           

          
           if (Cmd.ExecuteNonQuery() > 0)
           {

                   Con.Close();
                   Response.Write("Done..");
           }


          
       }


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

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