Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have used a sqlite reader but it is not reading my query

try
{
    string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "veDatabase.db");
    using (SqliteConnection db =
       new SqliteConnection($"Filename={dbpath}"))
    {
        db.Open();


        SqliteCommand selectCommand = new SqliteCommand("SELECT * FROM TABLE_EMPLOYEE  EMP_ID, EMP_SITEID, EMP_GroupID,   EMP_PROFILEID ", db);

        SqliteDataReader query = selectCommand.ExecuteReader();


        while (query.Read())
        {
            EmployeeItem s_item = new EmployeeItem();

            s_item.Id = query.GetInt64(1);

            empdetails.Add(s_item);
        }

    }
}
catch (Exception ex)
{

    Console.WriteLine(ex.Message);
}




            empdetails.Add(s_item);
        }


What I have tried:

this line is not executing
SqliteDataReader query = selectCommand.ExecuteReader();


SqliteCommand selectCommand = new SqliteCommand
             ("SELECT * FROM TABLE_EMPLOYEE  EMP_ID, EMP_SITEID, EMP_GroupID, EMP_PROFILEID ", db); 





my error is
        //SQLite Error 1: 'no such table: EMP_SITEID'.
Posted
Updated 29-Nov-22 21:39pm
v4
Comments
Graeme_Grant 30-Nov-22 3:26am    
what is the error message?
Ailiseu Brigitta 30-Nov-22 3:32am    
SQLite Error 1: 'no such table: EMP_SITEID'.

Yes, the error message is correct. Your query:
SQL
SELECT * FROM TABLE_EMPLOYEE  EMP_ID, EMP_SITEID, EMP_GroupID, EMP_PROFILEID

is asking:
Select "all" fields
From table named "TABLE_EMPLOYEE  EMP_ID, EMP_SITEID, EMP_GroupID, EMP_PROFILEID"

Change to
SQL
SELECT * FROM TABLE_EMPLOYEE

or
SQL
SELECT EMP_ID, EMP_SITEID, EMP_GroupID, EMP_PROFILEID FROM TABLE_EMPLOYEE

This website will help you: SQL Tutorial - Essential SQL For The Beginners[^]
 
Share this answer
 
v2
Comments
Ailiseu Brigitta 30-Nov-22 4:32am    
i retified the problem but sql is not reading

while (query.Read())
Richard Deeming 30-Nov-22 4:33am    
Technically, it's "Select all fields from a table called TABLE_EMPLOYEE aliased as EMP_ID, cross joined to tables called EMP_SITEID, EMP_GroupID, and EMP_PROFILEID". It's the pre-ANSI92 syntax for joining tables, where the join conditions would be specified in the WHERE clause. :)
Ailiseu Brigitta 30-Nov-22 4:46am    
sorry guys i have created the table in name EMPLOYEE_SITEID and called it by EMP_SITEID my fault but i don't know how to read the item {
EmployeeItem s_item = new EmployeeItem();

s_item.Id = query.GetInt64(1);

empdetails.Add(s_item);
}
We can't help you: we have no access to your DB, no idea what the error message is, no idea how your connection has been established, and most important of all no idea what your query looks like - and you need all of those to even begin working out what the problem is.

So, it's going to be up to you.

Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

I'd start by looking at the actual SELECT query you are using: once the debugger hits the Execute reader line, look at the CommandText property of your selectComamnd closely.
The most common mistake beginners make is to assemble this text by concatenating variables into a string which is a huge mistake as it leaves your code open to SQL Injection as well as prone to failures. If you aren't using parameterised queries, that's a likely reason why you get a problem.
 
Share this answer
 
Comments
Ailiseu Brigitta 30-Nov-22 3:31am    
i am getting error called no such table: EMP_SITEID'.
OriginalGriff 30-Nov-22 3:43am    
And did you check your spelling in the database?

Plus ... you probably want to consider a JOIN rather than a blanket "SELECT FROM all of my tables" command. I suspect you are going to get a lot more rows than you expected!
Ailiseu Brigitta 30-Nov-22 4:22am    
i retified the problem but sql is not reading

while (query.Read())

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900