|
-
May 19th, 2012, 02:21 AM
#1
Thread Starter
Junior Member
combobox is displaying null values
the combox is bound database table,but it is not displaying the contents of table in database,instead it is displaying corresponding null values(blank).it is showing just "select" and the blank spaces corresponding to the number of items in database
here is my code:
Function combobfill() As DataSet
addconnection.Open()
Dim selectstring As String = "select materialsname from materialtype_table"
Try
Dim da As New SqlDataAdapter(selectstring, addconnection)
Dim ds As New DataSet
ds.Tables.Add("mymaterial")
ds.Tables("mymaterial").Columns.Add("material")
ds.Tables("mymaterial").Rows.Add("Select")
da.Fill(ds, "mymaterial")
Return ds
Catch ex As Exception
MsgBox(ex.Message)
Finally
addconnection.Close()
End Try
Dim dsd As DataSet = Nothing
Return dsd
addconnection.Close()
End Function
Dim ds As DataSet = combofillobj.combobfill()
ComboBox_Mtype.DataSource = ds.Tables(0)
ComboBox_Mtype.DisplayMember = "material"
-
May 19th, 2012, 02:34 AM
#2
Re: combobox is displaying null values
First thing, why are you creating a DataSet? All you're using is a single DataTable so why not just create a single DataTable? Second, while it's a small thing, you should be setting the DisplayMember before setting the DataSource.
As for the issue, what exactly are you expecting to see? You tell the ComboBox to display the contents of the "material" column and the only value you ever put in the "material" column is the value "Select". Look at your SQL query. Does it put any data in the "material" column? No it doesn't, so you don't see any of the data returned by the query.
By the way, what exactly is the point of the "Select" value? I mean, do you put the word "Type" into TextBoxes by default? Of course you don't, because you know that a computer user isn't so stupid that they don't know that they're supposed to type into a TextBox. Why is it that those same users suddenly become so stupid when confronted with a ComboBox that they can't work out that they're supposed to select an item without instruction?
-
May 19th, 2012, 03:11 AM
#3
Thread Starter
Junior Member
Re: combobox is displaying null values
SQL query is giving the output of material names on SQLServer,I used just datatable also.still it is showing blankspaces corresponding to material names on database.
the problem here is query is returning blank values,but the same query is giving output in sqlserver query browser
Last edited by suhailtholakkal; May 19th, 2012 at 03:29 AM.
-
May 19th, 2012, 03:31 AM
#4
Re: combobox is displaying null values
Your code:
Code:
Function combobfill() As DataSet
addconnection.Open()
Dim selectstring As String = "select materialsname from materialtype_table"
Try
Dim da As New SqlDataAdapter(selectstring, addconnection)
Dim ds As New DataSet
ds.Tables.Add("mymaterial")
ds.Tables("mymaterial").Columns.Add("material")
ds.Tables("mymaterial").Rows.Add("Select")
da.Fill(ds, "mymaterial")
Return ds
Catch ex As Exception
MsgBox(ex.Message)
Finally
addconnection.Close()
End Try
Dim dsd As DataSet = Nothing
Return dsd
addconnection.Close()
End Function
Dim ds As DataSet = combofillobj.combobfill()
ComboBox_Mtype.DataSource = ds.Tables(0)
ComboBox_Mtype.DisplayMember = "material"
You don't see the problem there? You tell the ComboBox to display one column but you put all the data in a different column. If you want to display the data then tell the ComboBox to display the column that contains all the data. You've got two different columns there: the one you create explicitly and the one the adapter creates implicitly. If you only want one column then only create one column and put all the data into that one column.
-
May 19th, 2012, 03:45 AM
#5
Thread Starter
Junior Member
Re: combobox is displaying null values
Last edited by suhailtholakkal; May 19th, 2012 at 04:33 AM.
-
May 19th, 2012, 04:31 AM
#6
Thread Starter
Junior Member
Re: combobox is displaying null values
i fixed the error..here the problem was,the column name i used in database should be same the name of column i added to table in order to assign datasource.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|