locked
Object must implement IConvertible error.. RRS feed

  • Question

  • User-1853313809 posted

    hai.. im having a "Object must implement IConvertible." error.. help me please..

    here the code..

        Sub authenticate(ByVal Sender As Object, ByVal e As EventArgs)

            Dim con As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString1"))
            Dim cmd As New SqlCommand
            Dim sda As New SqlDataAdapter
            cmd.CommandType = CommandType.StoredProcedure

            cmd.CommandText = "ETendering"

            cmd.Parameters.Add("@user", SqlDbType.NVarChar).Value = txtUsername
            cmd.Parameters.Add("@pass", SqlDbType.NVarChar).Value = txtPassword

            cmd.Connection = con

            Try

                con.Open()

                Dim FlagAuthentication1
                FlagAuthentication1 = "N"

                Dim rd1 As SqlDataReader = cmd.ExecuteReader()

                While rd1.Read()
                    If rd1("Password").ToString = txtPassword.Text Then
                        FlagAuthentication1 = "Y"

                        If rd1("Password").ToString = "1" Then
                            FormsAuthentication.RedirectFromLoginPage(User.Identity.Name.ToLower, False)
                            Response.Redirect("supplier.aspx")
                        End If

                        If rd1("Password").ToString = "0" Then
                            Response.Redirect("warning.aspx")
                        End If
                    Else
                        Response.Redirect("warning.aspx")
                    End If
                End While

                rd1.Close()

                If FlagAuthentication1 = "N" Then
                    Response.Redirect("warning.aspx")
                End If

            Finally
                con.Close()
            End Try

            con.Dispose()
            cmd.Dispose()

            con = Nothing
            cmd = Nothing
        End Sub

    ______________________________________________________________________________________________________

    the error was

    Object must implement IConvertible.

    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.InvalidCastException: Object must implement IConvertible.

    Source Error:

    Line 74:             FlagAuthentication1 = "N"
    Line 75:
    Line 76: Dim rd1 As SqlDataReader = cmd.ExecuteReader()
    Line 77:
    Line 78: While rd1.Read()


    Source File: c:\inetpub\wwwroot\eTendering\Login.aspx.vb    Line: 76


    I also not confident about the login coding i wrote.. that is because I refer it to other program and manipulate the coding. So, when the error occurs.. i doesn't know which part i should change it.. please help me.. thanks! :)

    Wednesday, January 26, 2011 8:20 PM

Answers

  • User-1181492241 posted

    You are setting parameter value as Texbox. You need to set the text in textbox.

      cmd.Parameters.Add("@user", SqlDbType.NVarChar).Value = txtUsername.Text
      cmd.Parameters.Add("@pass", SqlDbType.NVarChar).Value = txtPassword.Text         

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 11:02 PM

All replies

  • User-1181492241 posted

    What is the datatype of @user and @pass in stored procedure?

    Wednesday, January 26, 2011 10:34 PM
  • User-1853313809 posted

    What is the datatype of @user and @pass in stored procedure?

        @user nvarchar(50) = 'root',
        @pass nvarchar(50) = 'root'

    Wednesday, January 26, 2011 10:48 PM
  • User-1181492241 posted

    You are setting parameter value as Texbox. You need to set the text in textbox.

      cmd.Parameters.Add("@user", SqlDbType.NVarChar).Value = txtUsername.Text
      cmd.Parameters.Add("@pass", SqlDbType.NVarChar).Value = txtPassword.Text         

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 11:02 PM
  • User-1853313809 posted

    You are setting parameter value as Texbox. You need to set the text in textbox.

      cmd.Parameters.Add("@user", SqlDbType.NVarChar).Value = txtUsername.Text
      cmd.Parameters.Add("@pass", SqlDbType.NVarChar).Value = txtPassword.Text         


    thanks mr.Rajesh.. it solved.. erm.. how do we know the error occurs at that part?

    Wednesday, January 26, 2011 11:07 PM
  • User-1181492241 posted

    As the error occured on the line cmd.ExecuteReader() and it was conversion error, most probably it should be the type mismatch while setting values to comamnd parameter.

     

    Thursday, January 27, 2011 12:08 AM
  • User-1853313809 posted

    i see.. thank you.. :))

    Thursday, January 27, 2011 12:09 AM