Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET 4.0-从字符串转换为uniqueidentifier时转换失败!_C#_Asp.net_Webforms_Webmatrix - Fatal编程技术网

C# ASP.NET 4.0-从字符串转换为uniqueidentifier时转换失败!

C# ASP.NET 4.0-从字符串转换为uniqueidentifier时转换失败!,c#,asp.net,webforms,webmatrix,C#,Asp.net,Webforms,Webmatrix,我试图从.cshtml页面中的一个小函数中检索xml。这给了我一个错误。但是,这在控制台/表单环境中运行良好 它需要3个参数和1个异常 myDll.GetXML(year, username, uniqueidentifier, out ex); 当我运行这个页面时,我得到一个错误,“从字符串转换为uniqueidentifier时转换失败。” 或者一堆 System.Data.SqlClient.SqlException (0x80131904): Conversion failed whe

我试图从.cshtml页面中的一个小函数中检索xml。这给了我一个错误。但是,这在控制台/表单环境中运行良好

它需要3个参数和1个异常

myDll.GetXML(year, username, uniqueidentifier, out ex);
当我运行这个页面时,我得到一个错误,“从字符串转换为uniqueidentifier时转换失败。”

或者一堆

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)

   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)

   at System.CapTool.Server.DAL.DAL.GetCapabilitiesXML(Int32 fiscalYear, String majComId, String userName, Exception& exception)
在我的GetXML函数中,它只是将参数应用于存储过程。存储过程将返回我的对象。从那里我可以用.cshtml做所有有趣的事情

当我从SQLManagementStudio中手动输入值时,实际上我得到了正确的结果。同样,当我创建一个窗口表单应用程序时,我也得到了正确的结果

当涉及到.cshtml或.aspx页面时,我发现转换失败了

我已经尝试强制转换存储过程uniqueidentifier参数,但它仍然给我这个错误


我认为…它与唯一标识符有关…但我不知道该怎么做…

您的参数的类型是什么,它们是如何转换为SQL的

运行QueryAnalyzer并查看数据库中实际发生的情况,听起来您可能正在添加或排除““””,而SQL无法正确转换

myDll.GetXML(year, username, uniqueidentifier, out ex);
我在“WebMatrix”环境中工作。因此(目前)不能在“额外”之类的东西上启用语法高亮显示


将来,我将检查、检查并再次检查以确保我的参数有效。

如果您发布一些相关代码和/或数据,这将有所帮助。提供调用System.CapTool.Server.DAL.DAL.GetCapabilitiesXML(Int32 fiscalYear,String majComId,String userName,Exception&Exception)的代码,就这么简单。。。我忽略了一个愚蠢的错误。。。如果将来有人遇到此错误,只需检查、检查并再次检查,以确保您确实传递了一个有效的参数。