0

我已经在 Visual Studio 2010 中做一个项目大约一周了。我正在使用 vb 和一个简单的 sql 数据库。我正在尝试创建一个登录页面,以检查客户表中是否存在具有指定电子邮件和密码的记录。我已经到了超出调试深度的地步,任何人都可以看到导致错误的原因吗?

Login Web 表单的 Login.aspx.vb 文件如下所示:

Imports LoginTableAdapters

Partial Class Login
    Inherits System.Web.UI.Page

Dim LoginAdapter As LoginTableAdapter

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    Dim email As String
    Dim pass As String
    LoginAdapter = New LoginTableAdapter

    email = TextBox1.Text
    pass = TextBox2.Text

    If Me.LoginAdapter.QueryLogin(email, pass) Then
        Label1.Visible = True
    End If

    End Sub
End Class

QueryLogin() 的 SQL 如下所示:

SELECT        custemail, custpassword
FROM            customer
WHERE        (custemail = @Param1) AND (custpassword = @Param2)

这是只有在输入正确的用户/密码组合时才会发生的错误:

Server Error in '/DinnerNow' Application.
Input string was not in a correct format.
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.FormatException: Input string was not in a correct format.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[FormatException: Input string was not in a correct format.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +181
   Microsoft.VisualBasic.CompilerServices.Conversions.ToBoolean(String Value) +147

[InvalidCastException: Conversion from string "test@test.test" to type 'Boolean' is not valid.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ToBoolean(String Value) +337
   Microsoft.VisualBasic.CompilerServices.Conversions.ToBoolean(Object Value) +1304756
   Login.Button1_Click(Object sender, EventArgs e) +104
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553178
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
4

1 回答 1

1

你正在做的是

If Me.LoginAdapter.QueryLogin(email, pass)

这意味着返回到 this 的值应该是布尔类型。但是您的 sql 查询返回 custemail、custpassword。哪些是字符串类型。因此,布尔值不能与字符串类型进行比较。

将您的 sql 更改为

if((SELECT   Count(*) FROM customer WHERE (custemail = @Param1) AND (custpassword = @Param2))>0)
   Select Cast(1 as bit) IsCustomerExist
Else
    Select Cast(0 as bit) IsCustomerExist
于 2013-04-05T04:45:52.063 回答