你好堆栈溢出居民!这是我的第一篇文章,我希望能得到一些帮助。我已经搜索过,但因为我还是新手,所以我无法完全找到/理解我的答案。
我一直遇到这个错误:
消息:从字符串“”到类型“日期”的转换无效。文件:~/reports/pendingshipments.aspx 功能:btnExportXls_Click 堆栈跟踪:在 Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(String Value) at reports_default.btnExportXls_Click(Object sender, EventArgs e) in C:\Users\jet.jones\ Documents\ERIRoot\ERITitan\ERITitan.ssa\Web 应用程序\reports\pendingshipments.aspx.vb:第 75 行
这是我的代码:
在 App_code 上
**Public Function Reports_PendingShipments(ByVal intClientID As Integer, ByVal strMinDate As Date?, ByVal strMaxDate As Date?, ByVal xmlSiteID As String) As DataTable
'=================================================================================
' Author: Jet Jones
' Create date: 2013.05.28
' Description: Returns a data table with pending shipments for the sites specified
'=================================================================================
Dim objConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Titan").ToString)
Dim cmdGet As New SqlCommand("spReports_PendingShipments", objConn)
Dim parClientID As New SqlParameter("@ClientID", SqlDbType.Int)
Dim parMinDate As New SqlParameter("@MaxDate", IIf(Not strMinDate.HasValue, DBNull.Value, strMinDate))
Dim parMaxDate As New SqlParameter("@MaxDate", IIf(Not strMaxDate.HasValue, DBNull.Value, strMaxDate))
Dim parSiteID As New SqlParameter("@Sites", SqlDbType.Xml)
Dim objAdapter As New SqlDataAdapter(cmdGet)
Dim objTable As New DataTable
parClientID.Value = intClientID
parMinDate.Value = strMinDate
parMaxDate.Value = strMaxDate
parSiteID.Value = xmlSiteID
'set up the command object
cmdGet.Connection = objConn
cmdGet.CommandType = CommandType.StoredProcedure
'add the parameters
cmdGet.Parameters.Add(parClientID)
cmdGet.Parameters.Add(parMinDate)
cmdGet.Parameters.Add(parMaxDate)
cmdGet.Parameters.Add(parSiteID)
'open the connection
objConn.Open()
'execute the query and fill the data table
objAdapter.Fill(objTable)
'return the data table
Reports_PendingShipments = objTable
'clean up
objConn.Close()
objConn = Nothing
End Function**
我的 aspx.vb 页面以这种方式调用此函数(从查询中获取值):
objTable = Reports_PendingShipments(ucClientSearch.Value,
txtMinDate.Text, txtMaxDate.Text, strSites)
我正在传递变量 strSites 因为网站权限允许用户访问一个或多个站点位置,并且如果运行报告并且用户从下拉列表中选择“所有站点”,我只想发送他们的站点有权通过 XML。
如果我缺少任何信息,请告诉我!非常感谢任何人的迅速反应。