Click here to Skip to main content
16,021,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a data entry form with a local database attached. when I run it on my windows 8 it works like a charm but when I run it on other machine or on the same machine under windows 7. I get an error:

problem event name: CLR20r3
problem signature 01: windowsformsapplication.executive
problem signature 02: 1.0.0.0
problem signature 09: System.IO.FileNotFoundException
Posted
Comments
Silent Guardian 12-Mar-13 3:00am    
have u copied the database file?
System.IO.FileNotFoundException says that u havent copied the database or some other file associated to ur project
r5five 12-Mar-13 4:53am    
yes I have its the whole project folder. I just tried running it from windows 7
Pheonyx 12-Mar-13 10:37am    
Do you have any hard coded file paths in your application?
r5five 12-Mar-13 14:25pm    
what is the meaning of hard coded file paths
Pheonyx 12-Mar-13 16:21pm    
what i mean is are you telling the program to look for a specific file. E.G. coding something like "c:\my directory\..\myfile.extension". If you have something like that then maybe the file is in a different place on the windows 7 machine?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlServerCe;

namespace HDRDataEntryForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            BindDataToGrid();
        }
        private string _textFilters;
        private DataSet _ds;
        frmSearch _frmSearch = null;
        DataTable dt;
        DataRow dr;
        private void Form1_Load(object sender, EventArgs e)
        {
            loadEmployee();
            // TODO: This line of code loads data into the 'databaseDataSet.Mainform' table. You can move, or remove it, as needed.
            this.mainformTableAdapter.Fill(this.databaseDataSet.Mainform);

        }

        public void BindDataToGrid()
        {
            try
            {
                dataGridView1.DataSource = databaseDataSet.Tables[0].DefaultView;
                dataGridView2.DataSource = databaseDataSet.Tables[0].DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Seems like the database file is not where it should... \n\nError details: {0}", ex.Message), "Error loading sample data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

 //Search Form Area//

        public void searchgrid_TextChanged(List<field> fields)
        {
            System.Data.DataView dv = ((System.Data.DataView)dataGridView2.DataSource); //
            _textFilters = ""; //reset filters
            bool first = true; //to handle the " and "
            foreach (field f in fields)
            {
                if (f.Value.Length > 0) //only if there is a value to filter for
                {
                    if (!first) _textFilters += " and ";
                    _textFilters += f.Field + " like '%" + f.Value + "%'";
                    first = false;
                }

            }


            dv.RowFilter = _textFilters;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (_frmSearch == null)
            {
                //let's add a couple of columns
                List<field> fields = new List<field>();
                field f = new field();
                f.FriendlyName = "UserID";
                f.Field = "UserID";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Name";
                f.Field = "Name";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Age";
                f.Field = "Age";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Gender";
                f.Field = "Gender";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Family_Member_Relation";
                f.Field = "Family_Member_Relation";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Family_Member_Name";
                f.Field = "Family_Member_Name";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Shnong";
                f.Field = "Shnong";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Dong";
                f.Field = "Dong";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Grand";
                f.Field = "Grand";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Amount";
                f.Field = "Amount";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Phone_Number";
                f.Field = "Phone_Number";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Date_Registered";
                f.Field = "Date_Registered";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Date_Recieved";
                f.Field = "Date_Recieved";
                fields.Add(f);

                f = new field();
                f.FriendlyName = "Status";
                f.Field = "Status";
                fields.Add(f);



                _frmSearch = new frmSearch(fields);
                _frmSearch.TextChanged += new SearchContextChangedHandler(searchgrid_TextChanged);
            }
            _frmSearch.ShowDialog();
            this.btoReset.Visible = true;
        }

        private void btoReset_Click(object sender, EventArgs e)
        {
            {
                _frmSearch = null;
                _textFilters = "";
                System.Data.DataView dv = ((System.Data.DataView)dataGridView1.DataSource); //
                dv.RowFilter = _textFilters;

                this.btoReset.Visible = false;
            }
        }
        //Search Form End//

        //Edit and Update Form Start//

        public void loadEmployee()
        {
            SqlCeConnection con = new SqlCeConnection("Data Source=Database.sdf");
            try
            {
                SqlCeDataAdapter ADAP = new SqlCeDataAdapter("Select UserID, Name, Age, Gender, Family_Member_Relation, Family_Member_Name, Shnong, Dong, Grand, Amount, Phone_Number, Date_Registered, Date_Recieved, Status from Mainform", con);

                ADAP.Fill(databaseDataSet, "Mainform");
                this.dataGridView2.DataSource = databaseDataSet.Tables["Mainform"];
                databaseDataSet.GetChanges();
                dataGridView1.RefreshEdit();
                dataGridView2.RefreshEdit();
                this.mainformTableAdapter.Fill(this.databaseDataSet.Mainform);




            }
            catch (Exception)
            {
            }



        }

        private void btoedit_Click(object sender, EventArgs e)
        {
            frmUpdate f2 = new frmUpdate(this);
            f2.UserID = dataGridView2.CurrentRow.Cells[0].Value.ToString();
            f2.Name = dataGridView2.CurrentRow.Cells[1].Value.ToString();
            f2.Age = dataGridView2.CurrentRow.Cells[2].Value.ToString();
            f2.Gender = dataGridView2.CurrentRow.Cells[3].Value.ToString();
            f2.Family_Member_Relation = dataGridView2.CurrentRow.Cells[4].Value.ToString();
            f2.Family_Member_Name = dataGridView2.CurrentRow.Cells[5].Value.ToString();
            f2.Shnong = dataGridView2.CurrentRow.Cells[6].Value.ToString();
            f2.Dong = dataGridView2.CurrentRow.Cells[7].Value.ToString();
            f2.Grand = dataGridView2.CurrentRow.Cells[8].Value.ToString();
            f2.Amount = dataGridView2.CurrentRow.Cells[9].Value.ToString();
            f2.Phone_Number = dataGridView2.CurrentRow.Cells[10].Value.ToString();
            f2.Date_Registered = dataGridView2.CurrentRow.Cells[11].Value.ToString();
            f2.Date_Recieved = dataGridView2.CurrentRow.Cells[12].Value.ToString();
            f2.Status = dataGridView2.CurrentRow.Cells[13].Value.ToString();
            f2.passDgvValueToForm2();
            f2.ShowDialog();
            loadEmployee();
        }
 
Share this answer
 
Comments
Pheonyx 17-Mar-13 13:26pm    
Where is the code for the frmUpdate?

In particular the constructor code.

I see you are calling it here:

frmUpdate(this)

and I am wondering if this is the line that is erroring?
Search Form Code:
XML
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsFormsApplication4
{
    public partial class frmSearch : Form
    {
        public event SearchContextChangedHandler TextChanged;
        /// <summary>
        /// Build controls based on fields collection
        /// </summary>
        /// <param name="fields"></param>
        private void BuildControls(List<field> fields)
        {
            int top = 10;
            bool focused = false;

            #region Loop for each field
            foreach (field f in fields)
            {
                Label label = new Label();
                label.Text = f.FriendlyName + ":";
                label.Top = top;
                label.Left = 10;
                label.AutoSize = true;
                this.Controls.Add(label);

                TextBox textbox = new TextBox();
                textbox.TextChanged += new EventHandler(textBox_TextChanged);
                textbox.Tag = f.Field;
                textbox.Top = top;
                textbox.Left = 135;
                textbox.Width = this.Width - 180;
                if (!focused)
                {

                    textbox.Focus(); //the first control focused
                    focused = true;
                }
                top += 35;
                this.Controls.Add(textbox);
            }
            #endregion

            this.Height = top + 30;
        }

        public frmSearch(List<field> fields)
        {
            InitializeComponent();
            BuildControls(fields);
        }


        /// <summary>
        /// Returns field collection with filter values
        /// </summary>
        /// <returns></returns>
        private List<field> GetFilterValues()
        {
            List<field> fields = new List<field>();

            foreach (Control ctrl in this.Controls)
            {
                if (ctrl.GetType() == typeof(TextBox))
                {
                    field f = new field();
                    f.Field = ctrl.Tag.ToString();
                    f.Value = ctrl.Text;
                    fields.Add(f);
                }
            }
            return fields;
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            if (TextChanged != null)
                TextChanged(GetFilterValues());
        }
        private void frmSearch_Load(object sender, EventArgs e)
        {

        }
    }
}
 
Share this answer
 

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