Hi all plz help i need to search my database using data from the combo box which works fine
the problem that I an experiencing is that FIND function gives me a runtime error, saying the string is not
in the correct format plz help. here is the code that i used.

string data = this.cmbSearch.Items[this.cmbSearch.SelectedIndex].ToString();

                OleDbConnection conn = new OleDbConnection(strCon);
                OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Employee",conn);
                OleDbCommandBuilder oleBuilder = new OleDbCommandBuilder(adapter);
                DataSet ds = new DataSet();
                adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                     
                
                adapter.Fill(ds,"Employee");

                DataRow findrow;
                findrow = ds.Tables["Employee"].Rows.Find(data);
               
                if (findrow == null)
                {
                    MessageBox.Show("Please recheck your spelling", "Employee Not Found",
                       MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    
                }
                else
                {
                    string labeldata = this.cmbSearch.Items[cmbSearch.SelectedIndex].ToString();
                    form2.EmployeeDisplay(data, labeldata);
                    form2.Show();
                    form2.Text = this.cmbSearch.Items[cmbSearch.SelectedIndex].ToString();
                }

>FIND function gives me a runtime error, saying the string is not
in the correct format

Argument of Find method must be primary key column value. I think you are passing string instead of int value.

Please mark this thread as solved if you have found an answer to your question and good luck!

This article has been dead for over six months. Start a new discussion instead.