Results 1 to 5 of 5

Thread: Conversion Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    321

    Conversion Error

    Hi All

    Im connecting to my SQL Server Stored Procedure and It requires a '@Parameter' to perform the 'Stored Procedure'. Im inputting the Parameter to 'Me.tbxSearch.Text' but doesnt seem to like it. Any ideas how I can sort this out?

    Thanks

    Code:
    CapitalVisasCRMDataSet.EnforceConstraints = False
    
            Me.SpMainSearchTableAdapter.Fill(Me.CapitalVisasCRMDataSet.spMainSearch, Me.tbxSearch.Text)
    
            Me.lsvSearchResults.Items.Clear()
            Me.lsvSearchResults.BeginUpdate()
    
            Dim spMainSearchRow As CapitalVisasCRMDataSet.spMainSearchRow
    
            For Each spMainSearchRow In CapitalVisasCRMDataSet.spMainSearch.Rows
                Dim reportListItem As New ListViewItem
    
                reportListItem.Text = ""
    
                reportListItem.SubItems.Add(spMainSearchRow("CaseID").ToString) ' Case ID
    
                reportListItem.SubItems.Add(Microsoft.VisualBasic.StrConv(spMainSearchRow("Candidate"), VbStrConv.ProperCase).ToString) 'Candidate Name
    
                reportListItem.SubItems.Add(spMainSearchRow("Email").ToString) 'Email Address
    
                reportListItem.SubItems.Add(spMainSearchRow("Country").ToString) 'Country of Lead
    
                reportListItem.SubItems.Add(spMainSearchRow("Nationality").ToString) 'Country of Nationality
    
                reportListItem.SubItems.Add(spMainSearchRow.CustomerID) ' Customer ID
    
                reportListItem.SubItems.Add(spMainSearchRow("CaseWorker").ToString) 'Caseworker
    
                reportListItem.SubItems.Add(spMainSearchRow("Consultant").ToString) 'Consultant
    
                lsvSearchResults.Items.Add(reportListItem)
            Next
    
            lsvSearchResults.EndUpdate()
    
            spMainSearchRow = Nothing
    This is also the Stored Procedure Code
    Code:
    USE [CapitalVisasCRM]
    GO
    /****** Object:  StoredProcedure [dbo].[spMainSearch]    Script Date: 06/06/2010 13:38:55 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER Procedure [dbo].[spMainSearch]
    
    
    	@FilterText NVARCHAR(255)
    
    
    AS
    
    
    SELECT     tblCases.CaseID, tblCases.Candidate, tblCases.Product, tblEmails.Email, tblCustomers.Nationality, tblCustomers.Country, 
                          tblCompany.CompanyName AS [Company Name], tblCustomers.CustomerID, tblCases.Consultant, tblCases.CaseWorker
    FROM         tblCustomers LEFT OUTER JOIN
                          tblCases ON tblCustomers.CustomerID = tblCases.CustomerID LEFT OUTER JOIN
                          tblCompany ON tblCustomers.CustomerID = tblCompany.CustomerID LEFT OUTER JOIN
                          tblEmails ON tblCustomers.CustomerID = tblEmails.CustomerID
    GROUP BY tblCustomers.Country, tblCustomers.Nationality, tblCustomers.CustomerID, tblCases.CaseID, tblCases.Product, tblCases.Consultant, tblCases.CaseWorker, 
                          tblCases.Candidate, tblEmails.Email, tblCompany.CompanyName
    HAVING      (tblCustomers.Country = @FilterText) OR
                          (tblCustomers.Nationality = @FilterText) OR
                          (tblCustomers.CustomerID = @FilterText) OR
                          (tblCases.CaseID = @FilterText) OR
                          (tblCases.Product = @FilterText) OR
                          (tblCases.Consultant = @FilterText) OR
                          (tblCases.CaseWorker = @FilterText) OR
                          (tblCases.Candidate = @FilterText) OR
                          (tblEmails.Email = @FilterText) OR
                          (tblCompany.CompanyName = @FilterText)
    Attached Images Attached Images  

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

    Re: Conversion Error

    If caseID and CustomerID are numbers then you can't do this:
    (tblCustomers.CustomerID = @FilterText) OR
    (tblCases.CaseID = @FilterText) OR

    Since your FilterText is a string... when SQL encounters 12 (say for the CaseID) ... it tries to convert your FilterText (which is "h" ) to a number... "h" isn't a valid number and so the error is thrown.

    -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??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    321

    Re: Conversion Error

    Quote Originally Posted by techgnome View Post
    If caseID and CustomerID are numbers then you can't do this:
    (tblCustomers.CustomerID = @FilterText) OR
    (tblCases.CaseID = @FilterText) OR

    Since your FilterText is a string... when SQL encounters 12 (say for the CaseID) ... it tries to convert your FilterText (which is "h" ) to a number... "h" isn't a valid number and so the error is thrown.

    -tg
    Oh yah... your right.. but is there a work around to this?

    Thanks

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

    Re: Conversion Error

    Sure... don't include those fields in the query...

    -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
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    321

    Re: Conversion Error

    Quote Originally Posted by techgnome View Post
    Sure... don't include those fields in the query...

    -tg
    I tried something different and it works.

    Code:
    USE [CapitalVisasCRM]
    GO
    /****** Object:  StoredProcedure [dbo].[spMainSearch]    Script Date: 06/06/2010 15:25:00 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER Procedure [dbo].[spMainSearch]
    
    
    	@FilterText NVARCHAR(255)
    
    
    AS
    
    
    SELECT     tblCases.CaseID, tblCases.Candidate, tblCases.Product, tblEmails.Email, tblCustomers.LeadNationality, tblCustomers.LeadCountry, 
                          tblCompany.CompanyName AS [Company Name], tblCustomers.CustomerID, tblCases.Consultant, tblCases.CaseWorker
    FROM         tblCustomers LEFT OUTER JOIN
                          tblCases ON tblCustomers.CustomerID = tblCases.CustomerID LEFT OUTER JOIN
                          tblCompany ON tblCustomers.CustomerID = tblCompany.CustomerID LEFT OUTER JOIN
                          tblEmails ON tblCustomers.CustomerID = tblEmails.CustomerID
    GROUP BY tblCustomers.LeadCountry, tblCustomers.LeadNationality, tblCustomers.CustomerID, tblCases.CaseID, tblCases.Product, tblCases.Consultant, tblCases.CaseWorker, 
                          tblCases.Candidate, tblEmails.Email, tblCompany.CompanyName
    HAVING      (tblCustomers.LeadCountry LIKE '%' + @FilterText + '%') OR
                          (tblCustomers.LeadNationality LIKE '%' + @FilterText + '%') OR
                          (tblCustomers.CustomerID LIKE '%' + @FilterText + '%') OR
                          (tblCases.CaseID LIKE '%' + @FilterText + '%') OR
                          (tblCases.Product LIKE '%' + @FilterText + '%') OR
                          (tblCases.Consultant LIKE '%' + @FilterText + '%') OR
                          (tblCases.CaseWorker LIKE '%' + @FilterText + '%') OR
                          (tblCases.Candidate LIKE '%' + @FilterText + '%') OR
                          (tblEmails.Email LIKE '%' + @FilterText + '%') OR
                          (tblCompany.CompanyName LIKE '%' + @FilterText + '%')

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