我使用一個自定義的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
那麼,怎麼回事?