我使用一个自定义的ASP.NET控件,我发现这里:http://www.codeproject.com/Articles/5347/DataCalendar添加会话变量作为OleDbParameter - 运行到错误“
我已经使用了从上面的页面源文件下载,能够在一个模板作为我的自定义日历的起点,我的目标是只显示当前用户创建的事件,我通过创建一个名为“userName”的会话变量来完成此操作,并且我正在使用如下查询参数化它:
Function GetEventData(startDate As DateTime, endDate As DateTime) As DataTable
'--read data from an Access query
Dim con As OleDbConnection = GetConnection()
Dim cmd As OleDbCommand = New OleDbCommand()
cmd.Connection = con
cmd.Parameters.AddWithValue("@currentUser", Session("currentuser"))
cmd.CommandText = String.Format("Select EventDate, CreatedBy, Count(*) From EventInfo Where (CreatedBy = @currentUser) and EventDate >= #{0}# And EventDate <= #{1}# Group By EventDate", _
startDate, endDate)
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
da.Fill(ds)
con.Close()
Return ds.Tables(0)
End Function
不幸的是我收到此错误:
Parameter[0] '' has no default value.
我已经确保我登录,所以它不是没有User.Identity.Name值(我不认为)的问题。我在页面加载子中创建会话变量:
Sub Page_Load(o As Object, e As EventArgs)
Session("currentuser") = User.Identity.Name
End Sub
那么,怎么回事?