How to use multiselect from streamlit with pyodbc sql server

Is it possible to use a multiselect box with pyodbc ? While connecting to SQL SERVER database.

By using the selectbox the function works and it display all the distinct values in the selectbox
But i need to use a multiselect

I know that multiselect takes as argument a list whre this list is given by the return of distinct values of the required field in the db.

How this can be done ??
Its very important to me to know if its possible or not in order to know what to expect from streamlit.

@leb_dev did u get solution for this?
im facing the same issue

What is your issue exactly?

  • You donโ€™t know how to get a list of distinct values of the required field from the database?

  • You donโ€™t know how to pass the list to a multiselect?

  • Something else?

It is unclear to me what you want. Do you want a string with all the selected values separated by commas?

@Goyo
If in the above drop down if an user select Failed to understand customer issue due to poor listening skills Clearly did not listen as missed important information it should display as below

As the number of option user selects those many options should be captured in the database by comma separated

I donโ€™t get it, a comma separated what? A string?

Your expected result looks exactly like the list that multiselect would return. Is that not the result that you get? What do you get instead?

1 Like

The SQL insert has only one โ€˜slotโ€™ for values and youโ€™re trying to insert multiple values. Presumably one new row per value is what you want. So you should iterate over the selections list and run an insert per selection. Or, do it all in one go as documented here.

Of course, option1 is a list of four elements and the parentheses around it do nothing, so indeed you are passing four values to an operation with only one parameter. Try str(option1) instead.

cursor.execute(
    "INSERT INTO solvertest ([Reason for โ€˜We demonstrated listeningโ€™ being No]) Values(?)",
    (str(option1),)
)

@Goyo
Thanku so much
It helped me a lot :smiley:

@Goyo can we store xlsx/csv files in streamlit without using any database even after deploying?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.