1

I have a MySQL database containing of images and texts that want binding it to ListBox in WPF project; here is my code that have exception error, how can I fix that?

enter image description here

public DataTable GetTable(String query, String sortBy)
{
    String connString = "server=localhost;uid=root;pwd=root;database=database_clothes";
    connection = new MySqlConnection(connString);
    adapter = new MySqlDataAdapter(query, connection);
    DataTable dataTable = new DataTable();

    adapter.Fill(dataTable);
    dataTable.DefaultView.Sort = sortBy;
    return dataTable;
}
2
  • It says that you don't have database database_clothes on that server. Did you check that? Commented Sep 18, 2017 at 7:17
  • yes Chetan Ranpariya it exists on local Commented Sep 18, 2017 at 7:44

2 Answers 2

1

Just answering my question! the problem was not mysql authentication despite of error message, here was my problem in sql commands in xaml file where the table name "names" was not as mine:

        <ObjectDataProvider x:Key="NamesTable"
ObjectType="{x:Type local:DatabaseTable}"
MethodName="GetTable">
        <ObjectDataProvider.MethodParameters>
            <s:String>SELECT * FROM names</s:String>
            <s:String>Name</s:String>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
Sign up to request clarification or add additional context in comments.

Comments

0

this exception said taht your connection is invalid. i think the database name is not correct. after resolve this problem , you should map your datatable to observablecollection then can binde observablecollection to your ListBox

here you can find good description

How to bind ObservableCollection with Listbox in WPF

2 Comments

where is your link?

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.