problem in the datagrid

M

mero

hi to all;
i have in my site a datagrid that is used to show the data about the user who registered to the site(lastname,firstname,...).

the idea from this datagrid that the admin can view the data of each person who is registered to the site, and then he can choose one of them and delete him.

what i did is that in the final column i put a link button (btndelete) named "delete" in each row so when the admin click on the delete
button , the user who is in the same row should be deleted

so, in ItemCommand event of datagrid i wrote this code:

if(e.CommandName=="btndelete")
{
int userid=System.Convert.ToInt32(e.CommandArgument);

SqlConnection conn=new SqlConnection();

conn.ConnectionString="DataSource=(AMIRA);InitialCatalog=Northwind;Integrated Security=SSPI";

SqlCommand comm=new SqlCommand();

comm.Connection=conn;

comm.CommandText="delete userid from register where userid=@userid ";
comm.Parameters.Add("@userid",userid);
conn.Open();

comm.ExecuteNonQuery();

conn.Close();


}

after running, and when i clicked on button delete in the first row to delete the first user , an error appeared:

"Input string was not in a correct format"

and the error on line:

int userid=System.Convert.ToInt32(e.CommandArgument);

so , please if anyone know how to solve this problem, please reply to me as soon as possible

thanks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top