Results 1 to 6 of 6

Thread: Falling through to Error - HELP

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    34

    Falling through to Error - HELP

    Ok. I have querried this in Server Management Studio and The Record is there. I have the Item Code put together correctly prior to executing my query in VB; however, it keeps falling through to my error exception. Can anyone tell me what I'm doing wrong?

    Public Sub Does_Case_UPC_Exists()
    Dim Item_Case As String = String.Concat(TextBox1.Text, "-")
    Item_Case = String.Concat(Item_Case, TextBox2.Text)
    MsgBox(Item_Case)

    Using cn As New SqlConnection(ConnectionString)
    Using cmd As SqlCommand = cn.CreateCommand
    cmd.CommandText = "SELECT OITM.CodeBars As U_upc_Code FROM OITM WHERE ItemCode = " & String.Format(Item_Case)
    Try
    cn.Open()
    Dim o As Object = cmd.ExecuteScalar
    If o IsNot Nothing Then
    Me.TxtCaseUPC.Text = o.ToString
    End If
    cn.Close()
    Catch ex As Exception
    MsgBox("Item Does NOT exists in OITM table !")
    Application.Exit()
    End Try
    End Using
    End Using
    End Sub

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Falling through to Error - HELP

    Have you looked at the actuall SQL that is being generated and sent to SQL server? Could you post it here
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    34

    Re: Falling through to Error - HELP

    Is this what you are asking for ? If not please let me know what I need to post in addition to what I have.

    Private Const ConnectionString As String = "Server=CORKYS-SERVER;user id=sa;password=sa;database=Corkys_Prod"

    Private ReadOnly Property Connection() As SqlConnection
    Get
    Dim ConnectionToFetch As New SqlConnection(ConnectionString)
    ConnectionToFetch.Open()
    Return ConnectionToFetch

    End Get
    End Property

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Falling through to Error - HELP

    no.. your command string... the SQL ... your select statement... what is the sql that is generated?

    the first thing that strikes me as being off is your use of the string.format function... which I don't know why you are using it... as Item_Case already is a string, and you're not applying and formatting or anything.

    I suspect other thigns are wrong as well, but that's the first and obvious...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    34

    Re: Falling through to Error - HELP

    Ok. I figured out why it was falling through . The data for the one field I was trying to get is NULL. I now have to build that data then update it. Now that I have that data built out. It is throwing out a weird error referring to column name invalid referring to actual data instead of a column name. I'm sorry to have so many questions. I'm primarily a DBA with SQL and I have done a lot of VB in the past; however, I'm fairly new to VB .net and I appreciate any assistance I can get expanding my horizons.
    The following code is where it is erroring out on.

    Public Sub Insert_Case_UPC_OITM(ByVal UPC_Code As String)
    Dim Item_Case As String = String.Concat(TextBox1.Text, "-")
    Item_Case = String.Concat(Item_Case, TextBox2.Text)

    ' Update OITM Table with New UPC Code for the CodeBars field
    Dim adapter As New SqlDataAdapter
    Dim sql As String = "UPDATE OITM SET CodeBars = " & UPC_Code & " WHERE OITM.ItemCode = " & Item_Case
    MsgBox(sql)
    Try
    If ConnectionState.Closed Then
    Connection.Open()
    End If
    adapter.UpdateCommand = New SqlCommand(sql, Connection)
    adapter.UpdateCommand.ExecuteNonQuery()
    MessageBox.Show("Case UPC for Item has been updated !", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
    If ConnectionState.Open Then
    Connection.Close()
    End If

    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try
    End Sub

    The sql appears to be displaying correctly so I suspect it has something to do with the adapter commands in which it is trying to execute the code.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Falling through to Error - HELP

    Quote Originally Posted by tdwainet View Post
    It is throwing out a weird error referring to column name invalid referring to actual data instead of a column name.
    That points heavily towards an error in your SQL statement, which Gary and tg suspected.

    There are a couple of articles from our Database Development FAQs/Tutorials (at the top of this forum) which are relevant (particularly the second):

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