Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the code in c#..... which i m using.... but it is throughing asn exception....

protected void GVDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        

        if (e.CommandName == "Approved")
        {
                       
            GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
            int Id = Convert.ToInt32(GVDetails.DataKeys[row.RowIndex].Value.ToString()); // for this we have to set the "DataKeyNames="doc_id" in HTML file
            Response.Write("the doc_id is = "+Id);

            cn.Open();
                
            SqlCommand cmd = new SqlCommand("update tdocument set STAT=@STAT where doc_id="+Id+"",cn);
            cmd.Parameters.Add("@STAT", SqlDbType.VarChar,15,"APPROVED");
            cmd.ExecuteNonQuery();   // HERE THE EXCEPTION IS OCCURING ..........The parameterized query '(@STAT varchar(15))update tdocument set STAT=@STAT where doc_id=' expects the parameter '@STAT', which was not supplied.            cn.Close();
        }
        else if (e.CommandName == "Reject")
        {
            Response.Write("Reject");
        }
    }
Posted
Updated 15-Feb-12 23:06pm
v2
Comments
Varun Sareen 16-Feb-12 5:06am    
edit for: added pre tag
ythisbug 16-Feb-12 5:11am    
u mean to say u want to update in ur table column as stat field is pending to approved..??

1 solution

Dear Friend,

Try this:-

protected void GVDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
 
        if (e.CommandName == "Approved")
        {       
            GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
            int Id = Convert.ToInt32(GVDetails.DataKeys[row.RowIndex].Value.ToString()); // for this we have to set the "DataKeyNames="doc_id" in HTML file
            Response.Write("the doc_id is = "+Id);
 
            cn.Open();
            
            cmd.Parameters.Add("@STAT", SqlDbType.VarChar,15,"APPROVED");    
            SqlCommand cmd = new SqlCommand("update tdocument set STAT=@STAT where doc_id="+Id+"",cn);
            
            cmd.ExecuteNonQuery();   // HERE THE EXCEPTION IS OCCURING ..........The parameterized query '(@STAT varchar(15))update tdocument set STAT=@STAT where doc_id=' expects the parameter '@STAT', which was not supplied.            
           cn.Close();
        }
        else if (e.CommandName == "Reject")
        {
            Response.Write("Reject");
        }
    }
 
Share this answer
 
Comments
shweta9999 17-Feb-12 0:39am    
thnkyou so much varun..
your job is apprciated.

tnaks
shweta9999 17-Feb-12 0:40am    
thnkyou so much varun..
your job is appreciated...
thanks
Varun Sareen 17-Feb-12 11:25am    
your most welcome shweta :). Please rate the answer as well if it really helps you out :)

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