Nitol Biswas

Nitol Biswas

  • NA
  • 37
  • 1.5k

Input string was not in a correct format

Nov 29 2016 7:00 AM
I use this below code in .aspx file for delete Girdview row. 
 
Asp Code:
 
<asp:TemplateField HeaderText="mus_id">
<ItemTemplate>
<asp:LinkButton ID="lblDelete" CommandArgument='<%# Eval("mus_id") %>' CommandName="DeleteRow" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
 
C# Code
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "DeleteRow")
{
SqlConnection cs = new SqlConnection("Data Source=DESKTOP-3T94FQ0;Initial Catalog=RAMS;Integrated Security=False;UID=sa;Password=sa123;");
SqlCommand deleteCommand = new SqlCommand("DELETE FROM [tbl_musannet] WHERE [mus_id]= @mus_id",cs);
deleteCommand.Parameters.Add("@mus_id", SqlDbType.BigInt).Value = Convert.ToInt64(e.CommandName);
cs.Open();
deleteCommand.ExecuteNonQuery();
cs.Close();
}
}
 
But when I going to delete rows "Input string was not in a correct format" error is showing. 
Please help.
Thanks 
 

Answers (1)