Asp .Net: How to update database row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peerraghu
    New Member
    • Nov 2007
    • 30

    Asp .Net: How to update database row

    hi
    i want to place all the values of a paticular login member and i want to update his informatin,
    for example i want to update his phone no. and address etc..how can i do that ,right now iam developin web application by C#
    ,please sught out my problem.

    thank you in advance
    raghu
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    what have you done as yet that is not updating the details for you?
    A little bit of code here would help us find out why your code isint updating the database.

    You can also use teh debugger to trace the same

    Comment

    • peerraghu
      New Member
      • Nov 2007
      • 30

      #3
      Originally posted by Shashi Sadasivan
      what have you done as yet that is not updating the details for you?
      A little bit of code here would help us find out why your code isint updating the database.

      You can also use teh debugger to trace the same
      just check my code

      protected void Button1_Click(o bject sender, EventArgs e)
      {
      SqlConnection con = new SqlConnection(" user id=sa;password= vubrain;databas e=raghu;data source=vubrain4 ");
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandText = "userlogin" ;
      cmd.CommandType = CommandType.Tex t;
      SqlParameter para1;
      SqlParameter para2;
      SqlParameter para3;
      SqlParameter para4;
      SqlParameter para5;
      SqlParameter para6;
      SqlParameter para7;
      SqlParameter para8;
      SqlParameter para9;
      para1=cmd.Param eters.AddWithVa lue("loginname" ,t5.Text);
      para2 = cmd.Parameters. AddWithValue("l oginaddress", tb1.Text);
      para3 = cmd.Parameters. AddWithValue("l ogincity", t6.Text);
      para4 = cmd.Parameters. AddWithValue("l oginpostalcode" , t7.Text);
      para5 = cmd.Parameters. AddWithValue("l oginphone", t8.Text);
      para6 = cmd.Parameters. AddWithValue("l oginfax", t9.Text);
      para7 = cmd.Parameters. AddWithValue("l oginmobile", t10.Text);
      para8 = cmd.Parameters. AddWithValue("l oginemail", t11.Text);
      para9 = cmd.Parameters. AddWithValue("l oginwebsite", t12.Text);
      int intnum;
      con.Open();
      intnum = cmd.ExecuteNonQ uery();
      if (intnum > 0)
      {
      Label2.Text = "updated successfully";

      }
      else
      {
      Label2.Text = "updarted failed";
      }
      con.Close();

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        Hi,
        following is the line which is wrong.

        cmd.CommandText = "userlogin" ;

        This should have the update query in sql !!!
        Has to be an update query like
        "Update usertable Set name = @paramName, pwd = @password where userid = @userID"

        And add params accordingly!
        parameters are represnted by the @ symbol

        Comment

        • peerraghu
          New Member
          • Nov 2007
          • 30

          #5
          hi shashi thankyou for your reply
          but i did small coding in which i can update the table but it is updating every one's information but i want to update the profile only that person who logedin
          just go through my codding and make any changes

          protected void Button1_Click(o bject sender, EventArgs e)
          {
          SqlConnection con = new SqlConnection(" user id=sa;password= vubrain;databas e=raghu;data source=vubrain4 ");
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;
          cmd.CommandText = "update userlogin set loginname='"+t5 .Text+"',logina ddress='"+tb1.T ext+"',logincit y='"+t6.Text+"' ,loginfax='"+t9 +"' where loginuser=login user";
          con.Open();
          cmd.ExecuteNonQ uery();
          con.Close();


          }

          thank you in advance

          Comment

          Working...