Inner join among relations

I want to fetch data from three tables: role, permission, and right. I used inner join.

Code
SqlConnection con = Class3 .GetConnection();
public DataSet showoption1()
{
    string sql1 = "select  right.rightname,role.rolename
                   FROM permission
                   INNER JOIN ON right.rightid = permission.rightid
                   INNER JOIN role ON permission.roleid = role.roleid  ";
    SqlCommand cmd = new SqlCommand(sql1, con);
    SqlDataAdapter adptr = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    adptr.Fill(ds);
    DataTable table = ds.Tables[0];
    return ds;
}
Database Tables

Role

Role Id   Role name
  1       admin
  2       employee

Right

rifgtid    rightname
      1    view courses
      2    view assessmenttest

Permission (Associative)

permissionid    rightid     roleid
   1             1           2
   2             1           1

Answers


I'm not sure what you're asking but there is an error on your sql syntax

SELECT      right.rightname,
            role.rolename 
FROM        permission 
INNER JOIN  right ON right.rightid = permission.rightid 
INNER JOIN  role ON permission.roleid = role.roleid

I replaced INNER JOIN ON by INNER JOIN right ON

As a side note, dispose ADO.NET related objects (SqlConnection, SqlCommand, SqlDataAdapter)


If the table's name is RIGHT, then you need to delimit that name, since it's a reserved word, e.g.

SELECT      [right].rightname,
            role.rolename 
FROM        permission 
INNER JOIN  [right] ON [right].rightid = permission.rightid 
INNER JOIN  role ON permission.roleid = role.roleid

(Stealing @Claudio's query). But I'd actually recommend you revisit the schema and pick a different, non-reserved name for the table.


Need Your Help

ShortCode Wordpress doesnt work

php wordpress shortcode

I have a shortcode that I put in my post but somehow it doent execute for some reasong. Here is the code I have:

Getting user input from Win32 C++. WPARAM casted as int?

c++ winapi input keyboard

I'm working on a pre-existing codebase and I'm looking to have the user type any 1-2 digits followed by the enter key at any time during the code being run and pass that number to a function. Curr...