Solved

ODBC.Net Connections

Posted on 2003-11-02
2
258 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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