I am programming an application using SQL Server Compact Edition in which my program inserts some data from somewhere to a local database. My database table has columns like: username, enterdate, exitdate.
.. and so on.
Now I am trying to read a special row of my data and then add that row to a listview, but when I use the SqlCeDataReader
and its Read();
method, it adds duplicate items to my listview. For example if my needed row is at the 9th index of the database, I mean when my desired row for example is in the 9th row of my database when I SELECT
it using WHERE
and then I read it, it adds 9 duplicate items with the same row data I need to my listview.
I am using Microsoft Visual Studio 2008 Express Edition.
Con.ConnectionString = "data source = |datadirectory|\\RoomDataBase.sdf";
Con.Open();
cmd.Connection = Con;
cmd.CommandText = "SELECT * FROM room WHERE username = '" + user + "'";
SqlCeDataReader reader1 = cmd.ExecuteReader();
if (reader1.Read() )
{
dblogger(user + " Entered and WAS in list");
//my problem happens here that the above line iterates
}
dblogger
is a void that adds a string to a list view
In fact my problem is that the inside of if{....}
iterates and iterates to number of the number of row in the database
I must tell you that when I SELECT
data from database using WHERE
I am sure that only one row matches the criteria, so to be sure about everything, the problem is from the Read()
procedure.
And I must mention you that this problem either happens when I use SqlCeResultSet
and then using it ReadFirst();
.
Special thanks to those who know the answer.