I am currently trying to grab some rows from a SQL Server database using C# that are of the following criteria:
- From the
RamResultsdatabase - in the
Resultstable - where the
Datecolumn is equal to the current date
I have the following so far:
// Open the same connection with the same connection string.
using (SqlCeConnection con = new SqlCeConnection(DatabaseControl.conString))
{
con.Open();
// Read specific values in the table.
using (SqlCeCommand com = new SqlCeCommand("SELECT Result FROM RamResults WHERE Date == @Form1.date", con))
{
SqlCeDataReader reader = com.ExecuteReader();
while (reader.Read())
{
int resultsoutput = reader.GetInt32(0);
MessageBox.Show(resultsoutput.ToString());
}
}
}
Using SELECT Result FROM RamResults WHERE Date == Form1.date throws an error:
There was an error parsing the query. [ Token line number = 1,Token
line offset = 43,Token in error = = ]
Although if I take out the WHERE statement e.g.
SELECT Result FROM RamResults
it works perfectly
Description
2 things
Use
=instead of==because this is the right equals operator inT-SQL.Your Query should be like this
SELECT Result FROM RamResults WHERE Date = @DateYou forget to pass in the parameter.
Sample