?
Solved

ODBC.Net Connections

Posted on 2003-11-02
2
Medium Priority
?
259 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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 …

752 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