filling the data in gridview by using join query

Posted by Farooq_torus under C# on 9/8/2011 | Points: 10 | Views : 2499 | Status : [Member] | Replies : 1
i have three tables

table 1:

userid, username, password

tabel 2:

userid, groupid


i want to show a username from table1 and name from table 3 in grid view.
i wrote a query as.

SqlDataAdapter da = new SqlDataAdapter("select users.username, from users,groups inner join users on roles.userid=users.userid inner join groups on roles.groupid=users.groupid", MAconn); 
but i am getting an error

System.NullReferenceException: Object reference not set to an instance of an object. at Default2.bind()


Posted by: SheoNarayan on: 9/8/2011 [Administrator] HonoraryPlatinum | Points: 25

First of all copy the SQL Statement you have written and paste into SQL Query Analyzer (SQL Server management studio) and run it, are you getting any record as a result? If not change the query and then use it along with SqlDataAdapter.

I strongly feel that the error you are getting has nothing to do with the SELECT statement, see on which line error is occuring and why the object that is throwing null reference is null.

Hope this helps.


Sheo Narayan

Farooq_torus, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response