使用Visual Studio从MS Access数据库通过C#中的特定字段搜索数据

问题描述 投票:-2回答:1

我正在一个项目上,我必须在那个项目中执行一项任务,我必须通过特定的文本或关键字从MS Access Database 2016文件中打印/查找数据,我会尽一切努力,但无法解决我的问题。问题,因此在尝试了所有方法之后,我决定将我的问题发布到此处以获取一些帮助来解决。我附加了我的代码,您可以看到,但是该代码没有执行任何操作,并且在尝试搜索任何内容时出现错误,错误是>

mscorlib.dll中发生类型'System.FormatException'的第一次机会异常附加信息:输入字符串的格式不正确。如果存在用于此异常的处理程序,则可以安全地继续执行该程序。

这是我在执行任务时面临的错误。

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();
    }
}

}

[我正在一个项目上,我必须在该项目中执行一项任务,我必须通过特定的文本或关键字来打印/查找MS Access Database 2016文件中的数据,但我会尝试所有措施,但...

c# database visual-studio ms-access-2016 icsharpcode
1个回答
0
投票

请仔细阅读:

© www.soinside.com 2019 - 2024. All rights reserved.