Solved

ODBC.Net Connections

Posted on 2003-11-02
2
242 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
2 Comments
 
LVL 6

Accepted Solution

by:
purpleblob earned 150 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now