Connecting Tech Pros Worldwide Forums | Help | Site Map

problem in the datagrid

mero
Guest
 
Posts: n/a
#1: Jun 21 '07
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);InitialC atalog=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...

Lit
Guest
 
Posts: n/a
#2: Jun 21 '07

re: problem in the datagrid


If you go into debug mode, do you see an integer for e.CommandArgument ?


<merowrote in message news:ewgDxi5sHHA.4424@TK2MSFTNGP04.phx.gbl...
Quote:
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);InitialC atalog=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...

Closed Thread