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