本文介绍了“System.InvalidCastException:指定的强制转换无效。”在connection.open期间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这里发生了什么。我在

VB.NET中编写了一个简单的应用程序来生成一个Crystal Report,我现在正试图将它移动到带有Crstal Enterprise的
ASP.NET。我希望我能告诉你

报告的工作原理......但是我甚至无法连接到数据库

:-)


我使用典型的:


Dim oConnection As New SqlConnection(strCon)

Dim cmdText As String =" SELECT * FROM viewLogin WHERE" &安培; _

viewLogin.username =''" &安培; strLogin& "''和viewLogin.password

" &安培; _

=''" &安培; strPW& "''和viewLogin.company_cd =''" &安培; strProperty

& "''"

Dim oDataAdapter As New SqlDataAdapter(cmdText,oConnection)

Dim oDS As New Data.DataSet()

oDataAdapter .SelectCommand.CommandText = cmdText

oConnection.Open()''###调试期间发生错误

oDataAdapter.Fill(oDS," viewLogin")

oConnection.Close()

那么,为什么这个在VB.NET中在同一个系统/ IDE上运行而不是在

ASP.NET中?

I have no idea what is going on here. I wrote a simple application in
VB.NET to generate a Crystal Report, and I am now trying to move it to
ASP.NET with Crstal Enterprise. I wish I could tell you how the
report works...but I can''t even get past connecting to the database
:-)

I use the typical:

Dim oConnection As New SqlConnection(strCon)
Dim cmdText As String = "SELECT * FROM viewLogin WHERE " & _
viewLogin.username = ''" & strLogin & "'' AND viewLogin.password
" & _
= ''" & strPW & "'' AND viewLogin.company_cd = ''" & strProperty
& "''"
Dim oDataAdapter As New SqlDataAdapter(cmdText, oConnection)
Dim oDS As New Data.DataSet()
oDataAdapter.SelectCommand.CommandText = cmdText
oConnection.Open() ''### Error occurs here during debug
oDataAdapter.Fill(oDS, "viewLogin")
oConnection.Close()
So, why does this work in VB.NET on the same system/IDE and not in
ASP.NET?

推荐答案




试试这个:


Dim cmdText As String =" SELECT * FROM viewLogin WHERE" _

& viewLogin.username& " =''' &安培; strLogin& "'''AND" _

& viewLogin.password& " =''' &安培; strPW& "'''AND" _&

viewLogin.company_cd& " =''' &安培; strProperty& ''"


我还建议将其移到存储过程中以避免SQL

注入攻击...


希望这会有所帮助!


jef



Try this:

Dim cmdText As String = "SELECT * FROM viewLogin WHERE " _
& viewLogin.username & " = ''" & strLogin & "'' AND " _
& viewLogin.password & " = ''" & strPW & "'' AND " _ &
viewLogin.company_cd & " = ''" & strProperty & "''"

I would also suggest moving this to a stored procedure to avoid SQL
injection attacks...

Hope this helps!

jef




试试这个:

昏暗cmdText As String =" SELECT * FROM viewLogin WHERE" _
& viewLogin.username& " =''' &安培; strLogin& "'''AND" _
& viewLogin.password& " =''' &安培; strPW& "'''"
_& viewLogin.company_cd& " =''' &安培; strProperty& "''"

我还建议将其移至存储过程以避免SQL
注入攻击...

希望这会有所帮助!

jef


Try this:

Dim cmdText As String = "SELECT * FROM viewLogin WHERE " _
& viewLogin.username & " = ''" & strLogin & "'' AND " _
& viewLogin.password & " = ''" & strPW & "'' AND "
_ & viewLogin.company_cd & " = ''" & strProperty & "''"

I would also suggest moving this to a stored procedure to avoid SQL
injection attacks...

Hope this helps!

jef




哦男人 - 没关系我说的话 - 我完全读错了。抱歉! :)


jef



Oh man - nevermind what I said - I totally read that wrong. Sorry! :)

jef





你的代码似乎对我有用。 ..问题是否有可能

与strCon一起?


FWIW,DataAdapter会自动打开和关闭连接

给你,所以没有必要明确地做...


祝你好运!!!



Your code seems to work for me...is there a chance that the issue could
be with the strCon?

FWIW, the DataAdapter will automatically open and close the connection
for you, so there''s no need to do it explicitly...

Good luck!!!


这篇关于“System.InvalidCastException:指定的强制转换无效。”在connection.open期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 11:40