我正在尝试从两个表格中显示gridview中的详细信息,登录名是树状结构,Admin,Manager,User
一个表是Maintenanceinfo,另一个表是UserDetails
以下是我的代码:
Private Sub fillgrid()
dt1 = Now.Year
If Convert.ToString(Session("userType")).ToLower() = "admin" Then
cmd.CommandText = "select sno, (SELECT UserName FROM UserDetails WHERE userid=Maintenanceinfo.userid) AS userid, Maintenance, January, February, March, April, May, June, July, August, September, October, November, December from Maintenanceinfo where year = " & dt1 & ""
ElseIf Convert.ToString(Session("userType")).ToLower() = "manager" Then
cmd.CommandText = "select sno, (SELECT UserName FROM UserDetails WHERE userid=Maintenanceinfo.userid) AS userid, Maintenance, January, February, March, April, May, June, July, August, September, October, November, December from Maintenanceinfo a,UserDetails b where a.userid=b.userid and b.Managerid= " & Session("userId") & " and year = " & dt1 & " "
Else
cmd.CommandText = "select sno, (SELECT UserName FROM UserDetails WHERE userid=Maintenanceinfo.userid) AS userid, Maintenance, January, February, March, April, May, June, July, August, September, October, November, December from Maintenanceinfo with (nolock) where userid= " & Session("userId") & " and year = " & dt1 & ""
End If
da = New SqlDataAdapter(cmd.CommandText, Con)
da.Fill(ds, "info")
Me.GridView1.DataSource = ds.Tables("info")
GridView1.DataBind()
' cmd.CommandText = "select isnull(count(*),0) from DM_Memberinfo m inner join DM_Dln d on m.memberid=d.dlnmemid where d.memberid=" & Session("uname") & " "
End Sub
当尝试以“admin”和“user”身份登录时,代码工作正常,但在尝试以“管理员”身份登录时,它无法正常工作并且无法找到“Maintenanceinfo.userid”
欣赏是否有人可以帮助我
谢谢
答案 0 :(得分:0)
对于经理部分,您已为Maintenanceinfo表定义了别名。所以你应该使用它或删除别名:
select sno, (SELECT UserName FROM UserDetails WHERE userid=a.userid)
AS userid, Maintenance, January, February, March, April, May, June, July, August,
September, October, November, December from Maintenanceinfo a,UserDetails b
where a.userid=b.userid and b.Managerid= " & Session("userId") & "
and year = " & dt1 & " "