I'm pretty new to using M-S Access Databases in Visual Studio and therefore I'm not familiar with the OLEDB syntax. I've managed to create this program using various internet sources. My program so far gets the user to log into a login form, it then tests the data against the username and password fields and if they match it then redirects the user to the second form, this then gathers data from an Access database using the name they've logged in with, however I keep getting the error "No value given for one or more required parameters." when it tries to execute the code which gathers data from the database depending on their name. This is my code so far:
private void Form2_Load(object sender, EventArgs e)
{
string username = lblName.Text;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Rhys\Documents\Visual Studio 2013\Projects\AssignmentTrackerV2\AssignmentTrackerV2\bin\Debug\ATDatabase.accdb");
DataTable dt = new DataTable();
con.Open();
OleDbDataReader dr = null;
OleDbCommand cmd = new OleDbCommand("SELECT [Name], [Surname], [Password], [ID] FROM MemberDetails WHERE [Name] = '" + username + "'", con);
//This is where the error is occuring.
**dr = cmd.ExecuteReader();**
while (dr.Read())
{
lblName.Text = (dr["Name"].ToString() + dr["Surname"].ToString());
lblCourseTitle.Text = (dr["CourseTitle"].ToString());
lblID.Text = "ID: " + (dr["MemberID"].ToString());
}
con.Close();
}
Any advice on how to fix this error would be appreciated and as stated before I am fairly new to OLEDB syntax and apologise if there is an easy solution, thanks!