vb.net – 为什么“使用”似乎在一个函数中被拒绝,但在另一个函数中没有问题?

vb.net – 为什么“使用”似乎在一个函数中被拒绝,但在另一个函数中没有问题?,第1张

概述使用此代码: Protected Function GetArgValsForCompanyName(coName As String) As String() Dim args(2) As String Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD= 使用此代码:

Protected Function GetArgValsForCompanyname(coname As String) As String()    Dim args(2) As String    Using con As New sqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),cmd As New sqlCommand("select Unit,MemberNo,CustNo from Customers WHERE Companyname = @Coname",con)        con.open()        cmd.CommandType = CommandType.Text        cmd.Parameters.Add("@Coname",sqlDbType.VarChar,50).Value = coname        Using reader As sqlDataReader = cmd.ExecuteReader            While reader.Read                args(0) = reader.Item(0).ToString()                args(1) = reader.Item(1).ToString()                args(2) = reader.Item(2).ToString()            End While        End Using    End Using    Return argsEnd Function

……我明白了:

Server Error in '/EMS/customerreportingnet' Application.--------------------------------------------------------------------------------    Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please revIEw the following specific error details and modify your source code appropriately. Compiler Error Message: BC30203: IDentifIEr expected.Source Error:line 94:         Dim args(2) As Stringline 95: line 96:         Using con As New sqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),line 97:               cmd As New sqlCommand("select Unit,con)line 98: Source file: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_categoryadmin.aspx.vb    line: 96     --------------------------------------------------------------------------------Version information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491

因此,“使用con”行被认为是问题所在.我注释掉了大部分代码只返回一些随机值,它运行正常.

但是,还有另一个“使用”:button1_Click事件处理程序使用using.是不是只因为没有点击按钮而抱怨?

实际上,当我点击按钮时,我确实收到了一个错误,但这不是关于使用的;这是因为我显然在按钮处理的表单上有太多控件(实际上是千位或标签/复选框对):

Server Error in '/EMS/customerreportingnet' Application.--------------------------------------------------------------------------------Operation is not valID due to the current state of the object. Description: An unhandled exception occurred during the execution of the current web request. Please revIEw the stack trace for more information about the error and where it originated in the code. Exception Details: system.invalIDOperationException: Operation is not valID due to the current state of the object.Source Error: An unhandled exception was generated during the execution of the current web request. information regarding the origin and location of the exception can be IDentifIEd using the exception stack trace below.  Stack Trace:     [InvalIDOperationException: Operation is not valID due to the current state of the object.]   System.Web.httpValueCollection.ThrowIfMaxhttpCollectionKeysExceeded() +4198079   System.Web.httpValueCollection.FillFromEncodedBytes(Byte[] bytes,EnCoding enCoding) +60   System.Web.httpRequest.FillinFormCollection() +189[httpException (0x80004005): The URL-encoded form data is not valID.]   System.Web.httpRequest.FillinFormCollection() +11196408   System.Web.httpRequest.get_Form() +119   System.Web.TraceContext.InitRequest() +1188   System.Web.TraceContext.VerifyStart() +133   System.Web.httpApplication.System.Web.IhttpAsyncHandler.BeginProcessRequest(httpContext context,AsyncCallback cb,Object exTradata) +11307449   System.Web.httpRuntime.ProcessRequestInternal(httpWorkerRequest wr) +452  --------------------------------------------------------------------------------Version information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491

那么第一块代码中的“使用”真的是问题吗?有没有办法继续使用它,还是我需要恢复到创建对象的olde- [fangl,fashion]方式?

解决方法 在VB.NET中,行继续符允许从编译器的角度将两行视为一行.这个字符是下划线,应该是该行的最后一个.

最新版本的VB.NET编译器已经基本上消除了这一要求,它具有足够的智能来理解语句的结束位置.
例如,在linqPAD 5.10中,不需要在两个using语句之间使用此字符.

相反,似乎您当前的编译器无法理解这一点,添加延续字符应该可以解决问题

Using con As New sqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),_      cmd As New sqlCommand("select Unit,con)
总结

以上是内存溢出为你收集整理的vb.net – 为什么“使用”似乎在一个函数中被拒绝,但在另一个函数中没有问题?全部内容,希望文章能够帮你解决vb.net – 为什么“使用”似乎在一个函数中被拒绝,但在另一个函数中没有问题?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232753.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存