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

  • SEARCH
  • Home
  • 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 7026603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:08:22+00:00 2026-05-28T00:08:22+00:00

I am writing a windows mobile application that uses SQL CE. It is not

  • 0

I am writing a windows mobile application that uses SQL CE. It is not returning any rows when I include the WHERE Barcode = @Barcode statement.

I am guessing this is because the value for Barcode has trailing spaces after it. So I want to use WHERE rtrim(Barcode) LIKE @Barcode. But it is giving me a SqlCeException saying “The specified argument value for the function is not valid.”

I’m sure I am missing something stupid here. Any help greatly appreciated.

Here is my code:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace ElectricBarcodeApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            System.Data.SqlServerCe.SqlCeConnection conn = new System.Data.SqlServerCe.SqlCeConnection(
            ("Data Source=" + (System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "ElectricReading.sdf") + ";Max Database Size=2047")));
            try
            {
                // Connect to the local database
                conn.Open();
                System.Data.SqlServerCe.SqlCeCommand cmd = conn.CreateCommand();

                SqlCeParameter param = new SqlCeParameter();
                param.ParameterName = "@Barcode";
                param.Value = textBarcode.Text.Trim();



                // Insert a row
                cmd.CommandText = "SELECT Location, Reading FROM Main2 WHERE rtrim(Barcode) LIKE @Barcode";
                cmd.Parameters.Add(param);

                cmd.ExecuteNonQuery();

                DataTable data = new DataTable();

                using (SqlCeDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        data.Load(reader);
                    }
                }
                if (data != null)
                {
                    this.dataGrid1.DataSource = data;
                }

            }

            finally
            {
                conn.Close();
            }



        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (ElectricReadingDataSetUtil.DesignerUtil.IsRunTime())
            {
                // TODO: Delete this line of code to remove the default AutoFill for 'electricReadingDataSet.Main2'.
                this.main2TableAdapter.Fill(this.electricReadingDataSet.Main2);
            }

        }
    }
}
  • 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-28T00:08:23+00:00Added an answer on May 28, 2026 at 12:08 am

    The problem is that you can’t RTRIM an NTEXT or TEXT column. This also applies to standard SQL Server.

    You have to convert it to NVARCHAR first:

    SELECT Location, Reading FROM Main2 WHERE rtrim(CONVERT(NVARCHAR, Barcode)) LIKE @Barcode
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net 3.5 application running on windows mobile professional that uses sql
I'm writing an application for windows mobile 6 and above that requires a local
I'm interessted in writing an application that is running on windows mobile. I've allready
I am writing an application for Windows Mobile where I want to display some
While making some final tests of a class-library that I'm writing for Windows Mobile
Maybe you can help me... I am writing a program in Windows Mobile that
I'm writing an application for a Windows Mobile phone in VB.Net, and I would
I´m writing a Compact Framework Application for Windows Mobile 6.5. The Application will be
I'm writing a compact framework 3.5 application for a windows mobile device. In this
I'm writing an Windows Mobile application and I'd like to get a list of

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.