Results 1 to 2 of 2

Thread: Integer or other format

  1. #1
    Join Date
    Sep 2010

    Integer or other format

    ids is formatted as an integer in the table "sessionregister".

    How do I get ids to work either show the value or be null?

    User1 = TextBox1.Text
    Pass1 = Password1.Value.ToString()
    cmdStr = "SELECT ids FROM sessionregister WHERE username=@username AND password=@password;"
    Using conn As New SqlConnection(connStr)
    Using cmd As New SqlCommand(cmdStr, conn)
    cmd.Parameters.AddWithValue("@username", User1)
    cmd.Parameters.AddWithValue("@password", Pass1)
    ids = cmd.ExecuteScalar()
    End Using
    Error code:
    Unable to cast object of type 'System.Int32' to type 'System.IDisposable'.

  2. #2
    Join Date
    Feb 2003
    Michigan, USA
    How are you declaring the "ids" variable? Is it being declared in a "Using" statement?

    Using ids as Int
    End Using
    You'll have to pardon my lack of knowledge about VB syntax, as I'm more familiar with C#.

    The "Using" statement allows you to declare a variable that will be disposed at the end of that code block, which works nice for database connections. The variable you declare in the "Using" statement must implement the System.IDisposable interface. Integer variables do not implement this interface, therefore you cannot declare a new integer variable in the "Using" statement.

    Using ids as Int
    End Using
    Using conn as new SqlConnection(...)
        ids as Int
    End Using
    You can declare a new integer variable inside the code block for the "Using" statement.

    Though it is difficult to know what the problem is because I don't see the line of code declaring the "ids" variable.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles