我正在使用在这里找到的自定义 ASP.NET 控件:http: //www.codeproject.com/Articles/5347/DataCalendar
我已使用源文件中的一个模板(可从上面的页面下载)作为我的自定义日历的起点。我的目标是只显示当前用户创建的事件。我通过创建一个名为“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
那么,怎么了?