I connot able to filter the current user record

Ibtisam

New member
Joined
Nov 30, 2021
Messages
4
Programming Experience
1-3
Hi,
I connot able to filter the current user record. I want to display the data of current user only. But I did not understand how to handl query.
here is the ss of login.
1638276355715.png

As I selected Student, and username =50 and pass=50 ,


and when i press he show button this will display all the record but i want only current user data :
1638276732458.png



here is the code :
Need to updation in sql command:
                conn.Open();
                    OleDbCommand cmd = new OleDbCommand();
                    cmd.Connection = conn;
                    OleDbDataAdapter sda = new OleDbDataAdapter(@"SELECT student.s_id, student.f_name, student.l_name, student.email, student.address, course.c_id, course.cname, resultdate.resultgrade FROM ((student INNER JOIN resultdate ON student.s_id = resultdate.s_id) INNER JOIN course ON resultdate.c_id = course.c_id)", conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView1.DataSource = dt;
                //dataGridView1.Text = dt.Rows.Count.ToString();
                conn.Close();
 
Looks like a SQL query question rather than a C# question. In your SQL statement, you need to add a WHERE condition limiting the rows to just the matching user id that you want.
 
Looks like a SQL query question rather than a C# question. In your SQL statement, you need to add a WHERE condition limiting the rows to just the matching user id that you want.
C#:
conn.Open();
                    OleDbCommand cmd = new OleDbCommand();
                    cmd.Connection = conn;
                //cmd.CommandText = @"SELECT student.f_name, student.l_name, student.email, student.contact_no, course.c_id, course.cname, resultdate.resultgrade FROM((student INNER JOIN resultdate ON student.s_id = resultdate.s_id) INNER JOIN course ON resultdate.c_id = course.c_id AND student.contact_no = course.cstatus AND resultdate.resultdate = course.cname)"; where s_id = '" + textBox1.Text + "'
                    OleDbDataAdapter sda = new OleDbDataAdapter(@"SELECT student.s_id, student.f_name, student.l_name, student.email, student.address, course.c_id, course.cname, resultdate.resultgrade FROM ((student INNER JOIN resultdate ON student.s_id = resultdate.s_id) INNER JOIN course ON resultdate.c_id = course.c_id) WHERE UserDetails.StudentId='"+comboBox1.Text+"' ", conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView1.DataSource = dt;
                //dataGridView1.Text = dt.Rows.Count.ToString();
                //conn.Close();
 
Last edited by a moderator:
Yikes! NEVER take user input and put it directly into your SQL queries. Obligatory cartoon to remind you of this:

exploits_of_a_mom.png
 
Where did that UserDetails table come from? I thought you were querying the student table?
 
Last edited:
Back
Top Bottom