1

OleDbError** Hello I am new on this site, I'm wondering on how to get the data from MS Access, it always give me this error.

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();
    }
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
CrX14
  • 11
  • 1
  • Take a look at: https://stackoverflow.com/questions/33642446/simple-c-sharp-connection-to-accdb-file and https://www.c-sharpcorner.com/UploadFile/c56872/connecting-C-Sharp-application-to-ms-access-database/ and https://stackoverflow.com/questions/9310498/trying-to-connect-to-accdb-database-with-c-sharp-and-net-4-0 and https://stackoverflow.com/questions/8302349/oledb-connection-to-access-database-accdb – AliNajafZadeh Nov 15 '21 at 05:05
  • No, not c-sharpcorner. Pay no attention to that one. The string concatenation burns the eyes. – madreflection Nov 15 '21 at 05:06
  • 2
    Take a look at this answer: https://stackoverflow.com/a/51156199 OLEDB doesn't use named parameters. Rather, it uses positional parameters with `?` placeholders. That might not be the only problem you have here but it's a start. – madreflection Nov 15 '21 at 05:10

0 Answers0