1

I have a database in ms-access and wanted to select from it,

I know my question is very simple but I couldn't find the solution for it

this is how I want to select:

public static void SearchRationCreatorName(string RationCreator)
    {
        string StrCon = System.Configuration.ConfigurationManager....
        OleDbConnection Connection = new OleDbConnection(StrCon);
        OleDbDataAdapter DataA = new OleDbDataAdapter
("Select * from tRations where tRations.RationCreator= [RationCreator]", Connection);

        DataTable Dtable = new DataTable();
        DataA.Fill(Dtable);

but instead of selecting one row it select all of records in that table

0

1 Answer 1

2

That didn't show up well in the comment. I think you mean

"Select * from tRations where RationCreator= '"+RationCreator+"'" 

The way you worded your title suggests you may want to use a string in place of a tablename but your code suggests otherwise. IF you wanted to know how to select from a dynamic table, let me know.

Also, this will select all rows that match rationcreator. If you only want one row, use:

"Select TOP 1 * from tRations where RationCreator= '"+RationCreator+"'"

with or without an ORDER BY predicate

Sign up to request clarification or add additional context in comments.

3 Comments

In Access, you use a single quote to show text, and the # sign to show date. So a number is WHERE myNum = 6. Text is WHERE fName = 'Bill' and date is WHERE myBirthday=#04/08/2000#
that was all I need now and in the future, tanks for your very complete answer, it helped a lot
Glad to help... take care!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.