I am working on a project and i have to perform a task in that project that i have to print/find data from a MS Access Database 2016 File through a specific text or keyword i'll try everything but can't solve my problem so after trying everything i decided to post my problem here to get some help to solve it. I attached my code you can see that but that code doesn't performing any thing and i got a error while try to search anything the error is
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. If there is a handler for this exception, the program may be safely continued.
This is the error I am facing while perfroming the task.
namespace Vechile_Registration_System
{
public partial class Verification : Form
{
public Verification()
{
InitializeComponent();
}
private void Verification_Load(object sender, EventArgs e)
{
}
private void btnsearch_Click(object sender, EventArgs e)
{
searchDataBase();
}
private void searchDataBase()
{
string strsearch = txtsearch.Text.Trim().ToString();
StringBuilder sb = new StringBuilder();
vehicleBindingSource.Filter = string.Format("[Registration No] LIKE '%{0}%'", strsearch);
string strFilter = sb.ToString();
vehicleBindingSource.Filter = strFilter;
if (vehicleBindingSource.Count != 0)
{
dataGridView1.DataSource = vehicleBindingSource;
}
else
{
MessageBox.Show("No Records Found. \n The Vehcile may not register or you have enter wrong Registration Number.");
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Form1 MMenu = new Form1();
MMenu.ShowDialog();
}
}
}
PLEASE READ CAREFULLY:
We are making the first change in Verification.cs file. Change the Verification_Load exactly like this:
private void Verification_Load(object sender, EventArgs e)
{
vehicleTableAdapter.Fill(vehicleDataSet.Vehicle);
// If you want the grid view to show no data at the beginning
// Uncomment the following line
// vehicleBindingSource.Filter = "1 = 0";
}
Please apply these steps exactly as they are suggesting:
btnsearch_Click
And that's all.
Hope this helps.
Please mark as answer if it does
**** ORIGINAL ANSWER ****
This should solve your problem.
Please use exactly this code.
private void searchDataBase()
{
string strsearch = txtsearch.Text.Trim().ToString();
StringBuilder sb = new StringBuilder();
vehicleBindingSource.Filter = string.Format("[Registration No] LIKE '%{0}%'", strsearch);
if (vehicleBindingSource.Count != 0)
{
dataGridView1.DataSource = vehicleBindingSource;
}
else
{
MessageBox.Show("No Records Found. \n The Vehcile may not register or you have enter wrong Registration Number.");
}
}