Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC.Net Connections

Posted on 2003-11-02
2
Medium Priority
?
262 Views
Last Modified: 2010-04-16
I'm going mad just trying to get the correct result from an Access database through ODBC using C#. I've got the following:

private void dishNameBox_TextChanged(object sender, System.EventArgs e)
            {
                  textBox1.Text = "";
                  string sql = "SELECT d_name FROM dishes WHERE d_name LIKE '" + dishNameBox.Text.Trim() + "*'";

                  OdbcCommand command = new OdbcCommand(sql, conn);
                  conn.Open();

                  OdbcDataReader reader = command.ExecuteReader();
                  while (reader.Read())
                  {
                        textBox1.Text += reader.GetString(0);
                  }
                        
                  reader.Close();
                  conn.Close();
            }

where conn is a tested OdbcConnection. The problem is that the reader OdbcDataReader doesn't want to return anything even when the query should (I've tested it directly in Access). In fact, when I remove the 'WHERE' part of the SQL, it returns all of the d_names as required.

Any ideas?
0
Comment
Question by:_WolfyUK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
purpleblob earned 600 total points
ID: 9666788
I notice you are using an asterix * for your wildcard character. I realize this works in Access, but the usual wildcard is % which is used for SQL in general.

Just to check this I set up an OdbcDataAdapter and went through the process of setting up a LIKE query using % and this works, whereas * doesn't appear to work in my tests.

Hope this helps
0
 

Author Comment

by:_WolfyUK
ID: 9666877
I first used a % when I was having other problems and copied the SQL to Access... and it failed so I replaced it with a *. But ODBC seems to like converting things like that when it wants to, so switching this back to a % worked fine. Cheers!

Why does my customer have to use this dodgy software?  :(
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question