Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to change the
Pending
into
verified
in a gridview by clicking the button(verify) and save it into the database.

What I have tried:

i have tried this code
protected void lnkBtnAccept_Click(object sender, EventArgs e)
  {
      try
      {
          var AcceptLink = (Control)sender;
          GridViewRow row = (GridViewRow)AcceptLink.NamingContainer;
          string Id = row.Cells[1].Text;
          DbCommand cmd = DataAccess.CreateCommand();
          //cmd.CommandText = SP.verifyPAN;
          cmd.CommandText = "update membermaster set VerifyPAN =1 where appmstregno='"+ row.Cells[1].Text+"'";
          cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "AppMstRegNo", DbType.String, Id));
          //cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "veryfy", DbType.String, 1));
          int i = DataAccess.ExecuteNonQuery(cmd);

          if (i > 0)
          {
              BindPaymentGrid();
          }
      }
      catch
      {

      }
  }



In the above if verifypan
(column name in table)
value is 0 then it shows pending and verifypan
(column name in table)
value is 1 it shows verified in a gridview but above code is not working please help me to solve this problem as soon as possible.
Posted
Updated 21-Apr-20 4:54am

1 solution

Why did you choose to concatenate the user entered text into the SQL Command Text, when you have a Parameter set up? Do you realize that this opens you up to SQL Injection, which has been documented for over 20 years and is still the number 1 application vulnerability?

To fix this and to shortcut your process of adding in the parameter; try this out
C#
cmd.CommandText = "update membermaster set VerifyPAN =1 where appmstregno=@AppMstRegNo";
cmd.Parameters.AddWithValue("@AppMstRegNo", row.Cells[1].Text);
A second suggestion would be to actually do something with that Catch block- perhaps define a variable with the exception and log that or something else to allow debugging to view the exception.

As for your problem at hand, if it is still occurring with; this is going to be more of a debugging issue to see what values are coming into this block of code and seeing if they are what you expect. And if they are correct, why isn't the database finding the desired record?
 
Share this answer
 
Comments
Member 14743579 21-Apr-20 11:27am    
this command is not working any other solution
MadMyche 21-Apr-20 11:56am    
Have you debugged line by line? Are there exceptions in the catch block?
Member 14743579 21-Apr-20 11:34am    
i have used this sql command into the another file and provide a link of sql command here. i have used code for getting a solution easily.
MadMyche 21-Apr-20 11:56am    
While it may seem harder at first, once you use parameters on a regular basic it becomes easier and and cleaner. You don't have to worry about single quotes around text or vulnerabilities, and when debugging you can go through line by line to see what parameters have what values. It may take longer initially (for now) but you save a lot of time debugging.
"Quick" is not a good reason to be sloppy, and often times you don't get back to making it proper

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900