I have the following method that uses to search for a text in a table
protected void fillGridView(int followingID, string text)
{
SqlCommand myCommand = new SqlCommand("select t.*,u.firstName,u.lastName,u2.firstName as afirstName,u2.lastName as alastName ,i.icon,ii.iconPath as taskIcon, iii.iconPath as seenIcon,f.fileName,f.fileID from tasks as t inner join users as u on u.userID=t.addedBy inner join users as u2 on u2.userID=t.attachTo inner join priorityIcons as i on t.priority=i.priorityID inner join icons as ii on t.status=ii.iconName inner join icons as iii on t.isNew=iii.iconName left join files as f on t.fileID=f.fileID where t.followingID=@followingID and t.firstName LIKE '%asd%'");
myCommand.Parameters.AddWithValue("@followingID", followingID);
myCommand.Parameters.AddWithValue("@text", text);
DBAccess db = new DBAccess();
DataSet ds = db.select(myCommand);
SqlDataAdapter adapter = new SqlDataAdapter();
tasksRepeater.DataSourceID = null;
tasksRepeater.DataSource = ds.Tables[0]; //Here the exception appear because the dataset ds is "null"
tasksRepeater.DataBind();
tasksCounter();
}
And the exception Message is "Object reference not set to an instance of an object."
but when i exchange sql statement above with the following one, the code runs successfully
SqlCommand myCommand = new SqlCommand("select t.*,u.firstName,u.lastName,u2.firstName as afirstName,u2.lastName as alastName ,i.icon,ii.iconPath as taskIcon, iii.iconPath as seenIcon,f.fileName,f.fileID from tasks as t inner join users as u on u.userID=t.addedBy inner join users as u2 on u2.userID=t.attachTo inner join priorityIcons as i on t.priority=i.priorityID inner join icons as ii on t.status=ii.iconName inner join icons as iii on t.isNew=iii.iconName left join files as f on t.fileID=f.fileID where t.followingID=@followingID");
so what is the problem!?