Create listbox based on contents of table
-
Newbie requiring help to something which is no doubt very simple! I have written a small application which gathers Company Name data from an Access table. I've also got a ValueMember set up which I am using to display the path to the mdb file used for the Company so that the user can see where the data is located, and it is also allowing me to offer the user a button so that they can open an Explorer window to go straight to the location of the file. My problem is that if the Company Name field is blank, I want to display some text (other than a blank) in the list box. The code snippet so far is: ********************************************* strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) ********************************************* This works well, and I can see the contents of my database in the listbox - its just that I can't get it to overwrite any blank entries in the listbox (if it finds any) with something which may be more meaningful to the user. Hope you can help.
-
Newbie requiring help to something which is no doubt very simple! I have written a small application which gathers Company Name data from an Access table. I've also got a ValueMember set up which I am using to display the path to the mdb file used for the Company so that the user can see where the data is located, and it is also allowing me to offer the user a button so that they can open an Explorer window to go straight to the location of the file. My problem is that if the Company Name field is blank, I want to display some text (other than a blank) in the list box. The code snippet so far is: ********************************************* strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) ********************************************* This works well, and I can see the contents of my database in the listbox - its just that I can't get it to overwrite any blank entries in the listbox (if it finds any) with something which may be more meaningful to the user. Hope you can help.
i am just guessing now but try something like this
if list1.additem = "" then (insert your code here)
-
i am just guessing now but try something like this
if list1.additem = "" then (insert your code here)
Thanks for that - but the listbox is, I think, already created and populated during the Fill process. What I'm struggling to do is get it to go and interogate the contents of dataset and build the listbox contents based on the condition that you've mentioned. I've thought about passing the contents of the database to an array, checking the contents, and passing that to the listbox, but I don't know how to do it. Any more thoughts?
-
Thanks for that - but the listbox is, I think, already created and populated during the Fill process. What I'm struggling to do is get it to go and interogate the contents of dataset and build the listbox contents based on the condition that you've mentioned. I've thought about passing the contents of the database to an array, checking the contents, and passing that to the listbox, but I don't know how to do it. Any more thoughts?
nope, sorry. But experiment with some code and it will hit you like a ton of bricks sooner or later ;)
-
nope, sorry. But experiment with some code and it will hit you like a ton of bricks sooner or later ;)
-
You could do the following in the query: SELECT IIf(IsNull([Test]),"Help",[TEST]) AS Expr1, TEST_TABLE.ID FROM TEST_TABLE;
OR strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) dim row as datarow for each row in dsCentlralDat1.Tables("TableName").Rows if isDbNull(row.item("CompanyName") orelse row.item("CompanyName") = "" then row.item("CompanyName") = "What you want" end if next Me.DataSource = dsCentlralDat1.Tables("TableName") Me.DisplayMember = "CompanyName" Me.ValueMember = "CompanyId" -- modified at 22:46 Tuesday 18th April, 2006
-
OR strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) dim row as datarow for each row in dsCentlralDat1.Tables("TableName").Rows if isDbNull(row.item("CompanyName") orelse row.item("CompanyName") = "" then row.item("CompanyName") = "What you want" end if next Me.DataSource = dsCentlralDat1.Tables("TableName") Me.DisplayMember = "CompanyName" Me.ValueMember = "CompanyId" -- modified at 22:46 Tuesday 18th April, 2006
Thanks - this works brilliantly!! :-D