首页 > 解决方案 > System.Data.OleDb.OleDbException:“没有为一个或多个必需参数提供值。” 一直显示

问题描述

OleDbError** 你好我是这个网站的新手,我想知道如何从 MS Access 获取数据,它总是给我这个错误。

public partial class MainWindow : Form
{
    OleDbConnection nc;
    public MainWindow()
    {
        InitializeComponent();
       nc = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\AfSMS\StudentManagementSystem\StudentManagementSystem\bin\Debug\MainStudData.accdb");
    }
 private void btnSearch_Click(object sender, EventArgs e)
    {
        nc.Open();
        OleDbCommand gd = new OleDbCommand("Select StudID,S_Name,F_Name,Address,BoD,Mob_Num,Email FROM StudInfo WHERE StudID=@dg1", nc);
        gd.Parameters.AddWithValue("@dg1", txtStud_ID.Text);
        OleDbDataReader dtr1;
        dtr1 = gd.ExecuteReader();
        if (dtr1.Read())
        {
            txtStudID.Text = dtr1["StudID"].ToString();
            txtS_Name.Text = dtr1["S_Name"].ToString();
            txtF_Name.Text = dtr1["F_Name"].ToString();
            txtAddress.Text = dtr1["Address"].ToString();
            txtBoD.Text = dtr1["BoD"].ToString();
            txtNum.Text = dtr1["Mob_Num"].ToString();
            txtMail.Text = dtr1["Email"].ToString();
        }
        else
        {
            MessageBox.Show("Data not Found", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        nc.Close();
    }

标签: c#oledbexception

解决方案


推荐阅读