Results 1 to 4 of 4

Thread: [RESOLVED] code error

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Resolved [RESOLVED] code error

    anyone see the trouble with this

    im trying to assign a value taken from the primary key field and increment it by one to use in an insert

    Dim z As Integer
    Dim max As String = "select z = MAX(c_msg_nr) from tb_orig_msg"
    Dim cmd1 As New SqlCommand(max, oSQLConn)
    z += 1
    it works 60% of the time, all the time.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: code error

    anyone see the trouble with this
    Yes.

    You've declared z as an integer, then tried to assign it inside the sql query string. You need to look at ExecuteScalar.

    http://msdn.microsoft.com/library/de...calartopic.asp

  3. #3

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: code error

    resolved thanks mendhak
    ive had some serious trouble with this
    genious

    my code if any ever has a similar problem

    Dim z As Integer
    Dim max As String = "select MAX(c_msg_nr)+1 as z from tb_orig_msg"
    Dim cmd1 As New SqlCommand(max, oSQLConn)
    cmd1.ExecuteNonQuery()
    z = cmd1.ExecuteScalar().ToString()


    thanks again
    it works 60% of the time, all the time.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] code error

    Btw, You don't need this line:

    cmd1.ExecuteNonQuery()

    Why did you include it?

Posting Permissions

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



Click Here to Expand Forum to Full Width