CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2013
    Posts
    6

    Unhappy Asp.net vb.net Problem

    Hi Everyone,

    I'am two thirds of the way along with my project but for this one line.
    I have 3 dropdown lists where I'am trying to take there selected values and update my database.
    My program seems to be getting these values yet they wont go in.

    My access database consists of:

    tbl_jobs
    jobId(autonumber)
    job(short Text)


    tbl_batch
    batchNumber(shortText)
    jobId(Number(longInt))
    startTime(date/Time)
    orignal(number(Int))

    I hope my attached pictures below highlight the problem further. Any help on getting this
    to work would be amazing. Thanks so much in advance, I really appreciate it.


    Name:  problemCode1.jpg
Views: 1866
Size:  98.2 KBName:  locals.jpg
Views: 1730
Size:  100.0 KB

  2. #2
    Join Date
    Feb 2013
    Posts
    6

    Re: Asp.net vb.net Problem

    I'am using visual studio 2010 Express and .net framework 4.0

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Asp.net vb.net Problem

    When concatenating strings you should use & rather than +
    When concatenating numeric vars into your string you should use the .ToString method which is the source of the error in your picture.

    MyString ="Some Text " & MyNumber.ToString & " More Text"
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Feb 2013
    Posts
    6

    Cool [SOLVED] Asp.net vb.net Problem

    Thanks DataMiser,

    That solved it.
    This is the updated line of code that I changed:
    Code:
    sqlString = "UPDATE tbl_batch SET orignal = " & shift & " WHERE batchNumber = '" & batch & "' AND jobId = " & job & " "

    Notice my batch parameter is a string so it must be wrapped in single quotes.
    You were absolutely right I was using the wrong concatenation for strings i.e. + is wrong, & is right ...
    In vb 6 it is ----> &
    in vb.net it is -----> +
    in vb.net and Mysql once again it is -----> &

    Thanks so much,
    I really appreciate it.

    Colm

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Asp.net vb.net Problem

    In vb 6 it is ----> &
    in vb.net it is -----> +
    in vb.net and Mysql once again it is -----> &
    Actually it is & in all versions of VB after VB3 including all versions of VB.Net

    + will work in all of them as well but you should always use & as of VB4 and later
    Last edited by DataMiser; February 11th, 2013 at 10:29 PM.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Asp.net vb.net Problem

    In vb 6 it is ----> &
    in vb.net it is -----> +
    in vb.net and Mysql once again it is -----> &
    Actually it is & in all versions of VB after VB3 including all versions of VB.Net

    + will work in all of them as well but you should always use & as of VB4 and later

    You should also be using .ToString on those values that are numeric vars. such as shift should be shift.ToString
    I take it that you do not have option strict enabled as it would be triggering an error complaining about mixing variable types if it were
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Feb 2013
    Posts
    6

    Re: Asp.net vb.net Problem

    I will correct that change thank you, i relatively new to this language and this help is great. when you say "option strict enabled" what does this mean and how would it be an advantage to me?

    Thank you,
    Really appreciate the help again

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Asp.net vb.net Problem

    Basically it forces a more strict method of coding and can help to eliminate runtime errors by alerting you to them when you are still in the IDE. There are options in the IDE for Option Explicit and Option Strict.

    Option Explicit forces you to declare all variables before using them.
    Option Strict forces you to use the correct variable types or conversions.

    For example you can combine a string and an integer if Option strict is off but if it is on you must convert one of them to the type of the other. You could add a double to a long without it on but with it will require you to make a conversion or use a different var.

    Basically these options force you to write better code and reduce the chance that your program will crash due to miss use of a variable
    Always use [code][/code] tags when posting code.

Tags for this Thread

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

Featured