burak Posted March 30, 2004 Posted March 30, 2004 Hello, I am filling a combobox from a dataset and want to add "--select table --" as the first value of this combobox. But my code is not working. What am I doing wrong? Thank you, Burak -------------- strsql = "select TABLE_NAME from user_tables " & _ "where TABLE_NAME <> '" + Replace(strTable, "'", "''") + "'" da = New OleDbDataAdapter(strsql, objconnection) da.Fill(ds, "tables") Dim firstItem As New ListViewItem("-- select table -- ", 0) lstFrgnTables.Items.Add(firstItem) ' fill lstFrgnTables combo box lstFrgnTables.DataSource = ds.Tables(0) lstFrgnTables.DisplayMember = "TABLE_NAME" lstFrgnTables.ValueMember = "TABLE_NAME" Quote
Administrators PlausiblyDamp Posted March 30, 2004 Administrators Posted March 30, 2004 Try adding the item after you've databound the list - otherwise it will reset the list as part of the databinding. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
burak Posted March 30, 2004 Author Posted March 30, 2004 When I do that , it comes back with "cast from datarowview to string is not valid" even when i add a tostring after it, io get an error ' fill lstFrgnTables combo box lstFrgnTables.DataSource = ds.Tables(0) lstFrgnTables.DisplayMember = "TABLE_NAME" lstFrgnTables.ValueMember = "TABLE_NAME" Dim firstItem As New ListViewItem("-- select table -- ", 0) lstFrgnTables.Items.Add(firstItem).ToString() Quote
JABE Posted March 31, 2004 Posted March 31, 2004 If your db supports UNION, you can try: strsql = "SELECT '-- select table --' UNION " & "select TABLE_NAME from user_tables " & _ "where TABLE_NAME <> '" + Replace(strTable, "'", "''") + "'" Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.