Error :
The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects
This is the error I'm getting when I run this code
MenuItem masterItem = new MenuItem((string)masterRow["Parentitem"]);
string mp =(string) masterItem.Value;
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@mp";
parameter.SqlDbType = SqlDbType.NVarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = mp;
string q = "select aspnet_PersonalizationPerUser.hasRights from Menu, aspnet_Users,
aspnet_Paths, aspnet_PersonalizationPerUser
where Menu.Parentitem = @mp
and Menu.Url = aspnet_Paths.Path
and aspnet_Paths.PathId = aspnet_PersonalizationPerUser.PathId
and aspnet_Users.UserName ='admin'
and aspnet_PersonalizationPerUser.UserId = aspnet_Users.userId ";
SqlCommand cm = new SqlCommand(q, conn);
cm.Parameters.Add(mp);
string b = (string)cm.ExecuteScalar();
I'm getting the exception when I'm adding parameter to the command.. Can u let me know the mistake..
from Menu, aspnet_Users, aspnet_Paths, aspnet_PersonalizationPerUser- this is very dangerous, if you ever miss one JOIN condition in the WHERE clause, you end up with a cartesian product! Also: your actual WHERE clause gets cluttered up with unnecessary conditions that really only serve as JOIN conditions.....FROM dbo.Menu m INNER JOIN dbo.aspnet_Paths p ON m.Url = p.Path INNER JOIN dbo.aspnet_PersonalizationPerUser ppu ON p.PathId = ppu.PathId INNER JOIN dbo.aspnet_Users usr ON ppu.UserId = u.userId WHERE Menu.Parentitem = @mp AND aspnet_Users.UserName = 'admin'