0

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();
                }
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by __avd
0

>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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.