Q:

C# cast is not valid

in my c# program I have a listview click event.Here is my code :
private void factorLV_Click(object sender, EventArgs e)
{
  try
{
    if (listview1.SelectedItems.Count == 0)
        return;
    listview2.Items.Clear();
    listview2.Show();
    DataClasses1DataContext db = new DataClasses1DataContext();
    List<ReportFactorResult> list = db.ReportFactor(Convert.ToInt32(listview1.SelectedItems[0].SubItems[0].Text)).ToList<ReportFactorResult>();
    foreach (ReportFactorResult val in list)
    {
        ListViewItem lst = new ListViewItem((Convert.ToString(listview2.Items.Count + 1)).ToString());
        lst.SubItems.Add(val.storeName);
        lst.SubItems.Add(val.Code.ToString());
        lst.SubItems.Add(val.factorNumber.ToString());
        lst.SubItems.Add(val.salePrice.ToString());
        listview2.Items.Add(lst);
    }
}
  catch(Exception ex)
{
   messageBox.show(ex.message);
}
}

when I run the program in visual studio it works properly.But as I Run the .exe out of the visual studio environment it meets this exception :

Specified cast is not valid

Image Below shows Exception without try catch. when I used try catch also I got "Specified cast..." message .
http://i59.tinypic.com/2qkl3qg.png
Also, in visual studio My program connected remotely to sql server management  but in outside visual studio I connected to Restored database in SQLExpress .

A:

After you have shown the stacktrace its more clear what your problem is. 
Currently your problem is in mapping your sql fields to ReportFactorResult. In particular ReportFactorResult has an int64 field which has a different field type in your database.
For further help we would need to see ReportFactorResult and your DB scheme. But if you look into your ReportFactorResult class and search for all int64 fields there you may find the problematic field by yourself.

