am trying to get the "role" which is a column name of a table

martnta

New member
Joined
Oct 29, 2021
Messages
1
Programming Experience
1-3
getting column anme from table:
     public bool checkUser()
        {
            bool check = false;
            SQLiteDataReader reader;
            using (SQLiteConnection con = new SQLiteConnection(GetConnetion()))
            {
                con.Open();

                cmd = new SQLiteCommand();
                try
                {
                    
                    string query = @"SELECT * FROM user where studentId = @studentID AND password =@password";
                    cmd.CommandText = query;
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    cmd.Parameters.AddWithValue("@studentID", studentId);
                    cmd.Parameters.AddWithValue("@password", password);

                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        log_role = reader.GetInt32("role");
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    check = false;
                }
            }
            return check;
        }
 
What issue are you running into in your attempt to get the "role" column value?

Also if all you need is the "role" column, change your SQL query to just have that column instead of using "*" which sends all the columns.
 
Back
Top Bottom