Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:48:39+00:00 2026-05-31T10:48:39+00:00

Using C#, .NET 4, SQL, visual studio 2010 and sql server manager 2008. Hi

  • 0

Using C#, .NET 4, SQL, visual studio 2010 and sql server manager 2008.

Hi guys, Seems like that same old easy to solve 101 question, but something has been bugging me.

My program runs a query and grabs the data and fills a dataset.

One of my fields is called pg (product group) and is set to a nvarchar(255).
most of the pgs are numbers like 30,50,12 etc but there are exceptions to this such as T1B and 50a.

For some reason I’m getting a conversion error.

“Conversion failed when converting the varchar value ‘T1B’ to an int”.

In my code all I’m using is data.fill();

Is it me or does it seem as though the data.fill is trying to assign the field PG as an integer because the first records it pulls looks like an int?
To be honest I always thought the fill would mimic whatever the sql data types were to its equivalent.

Hopefully its something easy that im overlooking.

If you wish to see more code, let me know and i will edit this post.

Many thanks

SQL Query

USE [ShaftData]
GO
/****** Object:  StoredProcedure [dbo].[GetSalesParetotemp]    Script Date: 03/14/2012       09:30:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetSalesParetotemp] 
@acct varchar(255), 
@From date, 
@Too date
AS
SELECT i.Acct,
   i.Name, 
   i.Document, 
   i.Part, 
   i.Qty, 
   i.Unit, 
   dbo.NEWPareto.Pareto, 
   i.pg,
   dbo.MyPgTable.PgName,
   i.[DateTime]

FROM   
OPENQUERY(SACBAUTO, 'SELECT dbo.iHeads.acct,
                            dbo.iHeads.name,
                            dbo.iLines.Document,
                            dbo.iLines.Part,
                            dbo.iLines.Pg,
                            dbo.iLines.Qty,
                            dbo.iLines.unit,
                            dbo.iHeads.[DateTime]  
                     FROM Autopart.dbo.iheads INNER JOIN     Autopart.dbo.iLines ON 
                     Autopart.dbo.Iheads.document =   autopart.dbo.iLines.document
                     GROUP By dbo.iHeads.acct,
                            dbo.iHeads.name,
                            dbo.iLines.Document,
                            dbo.iLines.Part,
                            dbo.iLines.Pg,
                            dbo.iLines.Qty,
                            dbo.iLines.unit,
                            dbo.iHeads.[DateTime]
                      ') i
left JOIN
  dbo.NEWPareto
ON 
i.Part collate SQL_Latin1_General_CP1_CI_AS = dbo.NEWPareto.Part 
left JOIN
dbo.MyPgTable 
ON  
  i.pg collate SQL_Latin1_General_CP1_CI_AS = dbo.MyPgTable.[pGroup]

WHERE
 (i.[DateTime] BETWEEN @From AND @Too) AND
 i.Acct = @acct 
 AND i.pg != 60
 AND i.pg != 61
 AND i.pg != 62

 GROUP BY i.Acct,
   i.Name, 
   i.Document, 
   i.Part, 
   i.Qty, 
   i.Unit, 
   dbo.NEWPareto.Pareto, 
   i.pg,
   dbo.MyPgTable.PgName, 
   i.[DateTime]

And here’s the method that calls it

try
        {
            string myConn = "Server=derp;" +
                            "Database=derp;" +
                            "uid=derp;" +
                            "pwd=derp;" +
                            "Connect Timeout=120;";

            string acct;// test using 1560

            SqlConnection conn = new SqlConnection(myConn);
            SqlCommand Pareto = new SqlCommand();
            BindingSource bindme = new BindingSource();
            SqlDataAdapter adapt1 = new SqlDataAdapter(Pareto);
            DataSet dataSet1 = new DataSet();
            DataTable table1 = new DataTable();

            acct = Acct;

            string fromDate = this.dateTimePicker1.Value.ToString("MM/dd/yyyy");
            string tooDate = this.dateTimePicker2.Value.ToString("MM/dd/yyyy");

            Pareto.Connection = conn;
            Pareto.CommandType = CommandType.StoredProcedure;
            Pareto.CommandText = "dbo.GetSalesParetotemp";
            Pareto.CommandTimeout = 120;

            Pareto.Parameters.AddWithValue("@acct", acct);
            Pareto.Parameters.AddWithValue("@from", fromDate);
            Pareto.Parameters.AddWithValue("@too", tooDate);

            SetCheckBoxValue(true);
            SetPictureBoxVisibility(true);
            //label1.Visible = true;
            adapt1.Fill(dataSet1, "Pareto");
            //label1.Visible = false;
            SetCheckBoxValue(false);
            SetPictureBoxVisibility(false);

            SetDataGrid(true, dataSet1, "Pareto", DataGridViewAutoSizeColumnsMode.AllCells);

            dataGridView1.AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode.AllCells);
        }
        catch (Exception execc)
        {
            MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
                            + " information:\n\n" + execc.Message + execc.StackTrace,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:48:41+00:00Added an answer on May 31, 2026 at 10:48 am

    I believe it’s SQL error caused by the query itself, because it mentions ‘varchar’, and if it were a .Net issue it would be saying ‘string’.

    Specifically:

    WHERE 
     (i.[DateTime] BETWEEN @From AND @Too) AND 
     i.Acct = @acct  
     AND i.pg != 60 
     AND i.pg != 61 
     AND i.pg != 62 
    

    That clause is breaking when it encounters one of the rows with the non-numeric pg value

    You could just change them to strings – i.e. '60', '61' and '62'

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL, SQL server manager 2008, c-sharp.net 4.0 and ms visual studio professional 2010:
Using: Microsoft SQL Server 2008 Microsoft Visual Studio 2010 C# .NET 4.0 WinForms Ok
I'm using Visual Web Developer 2010 Express and SQL Server 2008 R2 Management Studio
If I am using .Net and SQL Server 2008, what is the best way
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I'd like to know what are the benefits of using Sql Server 2008 over
I have an asp.net web application (c#) in visual studio 2010 that is heavily
I have installed the sp1 for visual studio 2010 and installed sql server ce
I am using visual studio 2010 my project is that, i want to encrypt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.