I have SQL Server Compact 3.5 database that contains account information. But everytime I call the function ExecuteReader I get this exception below:
The column name is not valid. [ Node
name (if any) = ,Column name = ID ]
But that is the correct column name. The column names are the following: Username, Password, Date Created, and etc.
Here is the code below:
SqlCeConnection connection = new SqlCeConnection(@"Data Source=C:\Users\Danny\Documents\Visual Studio 2010\Projects\Databinding Login Form\Databinding Login Form\MyDatabase#1.sdf; Password=*********");
connection.Open();
SqlCeCommand com = new SqlCeCommand("SELECT * FROM Accounts WHERE ID=Username", connection);
SqlCeDataReader reader = com.ExecuteReader();
if (username.Text == reader["Username"] as string && password.Text == reader["Password"] as string)
{
MessageBox.Show("Login Successfull!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Access Denied 5", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Do you have a column called “ID”?
It looks like you are asking for all accounts which have the same value in “Username” and “ID” columns? Did you meant to substitute “ID” for something?
Example