473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DropDown's DataSource/DataMember

Hi all,

I think I've stared at it until it's made me stupid(er?). What am I missing
about setting the list of the dropdown to display data pulled from a table?

//...
daPrepaid.Fill(dsPrepaid, "Seller");
cboSeller.DataSource = dsPrepaid.Tables["Seller"];
cboSeller.DisplayMember = "Name";
//...

When I assign the datasource, the dropdown's Text property changes to
"System.Data.DataRowView", which is then the only item in the list as well.
What's the stupid thing I'm not seeing?

TIA,

John
Jul 21 '05 #1
20 9361
Aren't you missing the cboSeller.ValueMember="Name"; <-- or whatever field ?

Greg

"John Spiegel" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I think I've stared at it until it's made me stupid(er?). What am I
missing
about setting the list of the dropdown to display data pulled from a
table?

//...
daPrepaid.Fill(dsPrepaid, "Seller");
cboSeller.DataSource = dsPrepaid.Tables["Seller"];
cboSeller.DisplayMember = "Name";
//...

When I assign the datasource, the dropdown's Text property changes to
"System.Data.DataRowView", which is then the only item in the list as
well.
What's the stupid thing I'm not seeing?

TIA,

John

Jul 21 '05 #2
John,

A change is in my opinion that "Name" is in the wrong case or even not in
your select..

That because you use three words cbo (combobox) and DropDown.

When cbo is a webpage dropdownlist than it is easy.
You miss
cboSeller.DataBind();

I hope this helps?

Cor
Jul 21 '05 #3
Hey Greg,

I had it in, but was getting an error. The strange thing is when I do
include ValueMember, the error message indicates a problem with binding to
DisplayMember, more specifically:

Could not bind to the new disply member.
Parameter name: newDisplayMember

A less abbreviated snippet...

OleDbCommand cmdPrepaid = conPrepaid.CreateCommand();
cmdPrepaid.CommandType = CommandType.Text;
cmdPrepaid.CommandText = "SELECT * FROM PrepaidSeller";
daPrepaid = new OleDbDataAdapter();
daPrepaid.SelectCommand = cmdPrepaid;
dsPrepaid = new DataSet();
conPrepaid.Open();
try
{
daPrepaid.Fill(dsPrepaid, "Seller");

cboSeller.DataSource = dsPrepaid.Tables["Seller"];
cboSeller.DisplayMember = "EntityName";
cboSeller.ValueMember = "CustKey";
//...
}

Thanks,

John

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Aren't you missing the cboSeller.ValueMember="Name"; <-- or whatever field ?
Greg

"John Spiegel" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I think I've stared at it until it's made me stupid(er?). What am I
missing
about setting the list of the dropdown to display data pulled from a
table?

//...
daPrepaid.Fill(dsPrepaid, "Seller");
cboSeller.DataSource = dsPrepaid.Tables["Seller"];
cboSeller.DisplayMember = "Name";
//...

When I assign the datasource, the dropdown's Text property changes to
"System.Data.DataRowView", which is then the only item in the list as
well.
What's the stupid thing I'm not seeing?

TIA,

John


Jul 21 '05 #4
Hey Cor,

That's interesting. It was the case! I had used mixed case naming in
another piece a few days ago--but that was in a typed data set.

Thanks!

John

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
John,

A change is in my opinion that "Name" is in the wrong case or even not in
your select..

That because you use three words cbo (combobox) and DropDown.

When cbo is a webpage dropdownlist than it is easy.
You miss
cboSeller.DataBind();

I hope this helps?

Cor

Jul 21 '05 #5
John,

Always the same problem and than I forgot it. You cannot use reserved SQL
words as items and AFAIK is "Name" one of them.

Cor
Jul 21 '05 #6
> A change is in my opinion that "Name" is in the wrong case or even not in
your select..
Cor, I don't believe case-sensitivity matters. No?

If this were a web page, the dropdownlist binding would look something like
this:

ddlSeller.DataSource = dsPrepaid.Tables["Seller"];
ddlSeller.DataTextField = "Name";
ddlSeller.DataValueField = "NameID"; <-- change appropriately
ddlSeller.DataBind()

' optional...
ddlSeller.Items.Insert(0, New ListItem("-select a Name-", ""))
If it is a combobox on winform, then:
cboSeller.DataSource = dsPrepaid.Tables["Seller"];
cboSeller.DisplayMember = "Name"
cboSeller.ValueMember = "NameID"; <-- change appropriately

Personally, considering all the troubles I've had databinding with winforms
(selectedindex=-1 issues, bound controls on tabcontrols, etc.) I prefer to
just iterate the datatable and manually add the items. But that's just me.

my .02
Greg

Greg
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... John,

A change is in my opinion that "Name" is in the wrong case or even not in
your select..

That because you use three words cbo (combobox) and DropDown.

When cbo is a webpage dropdownlist than it is easy.
You miss
cboSeller.DataBind();

I hope this helps?

Cor

Jul 21 '05 #7
Greg,

I saw that afterwards the same as you, that it could not be a webform
because that the dropdownlist has not a displaymember.

However than had John already sent a message replying you, I replied that
and after that he came with the answer that is was a case situation.

However I am still not sure if it was the case situation here or the wrong
itemname.

However the "case" is important in this situation (I have seen this to often
in this newsgroup while it is as well my own expirience). And the strange is
with that that SQL is case insensitive.

However just as far as I know.

Cor
Jul 21 '05 #8
Hmm.

I too was confused about winform and webform. :)

I thought you were onto something with the reserved word thing.
And the strange is with that that SQL is case insensitive.
"In SQL Server, object names can be case-sensitive, depending on the
character sort order that is installed. The sort order is chosen in SQL
Server Setup during installation. The default sort order in SQL Server
is dictionary order, case-insensitive.

If you need to change sort orders after installation, you must rebuild
your databases and reload your data."

John, try typing "execute sp_helpsort "in Query Analyzer to see what the
sort order and case-sensitivity is of your server. I know I am curious. :)

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl... Greg,

I saw that afterwards the same as you, that it could not be a webform
because that the dropdownlist has not a displaymember.

However than had John already sent a message replying you, I replied that
and after that he came with the answer that is was a case situation.

However I am still not sure if it was the case situation here or the wrong
itemname.

However the "case" is important in this situation (I have seen this to
often in this newsgroup while it is as well my own expirience). And the
strange is with that that SQL is case insensitive.

However just as far as I know.

Cor

Jul 21 '05 #9
I'm pretty certain it was the case. The name, otherwise, DID match the
database.

I suppose the case sensitvity makes sense regardless of SQL's view since
once we get it from the database, it's no longer got anything to do with SQL
and is instead up to .NET's interpretation.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Greg,

I saw that afterwards the same as you, that it could not be a webform
because that the dropdownlist has not a displaymember.

However than had John already sent a message replying you, I replied that
and after that he came with the answer that is was a case situation.

However I am still not sure if it was the case situation here or the wrong
itemname.

However the "case" is important in this situation (I have seen this to often in this newsgroup while it is as well my own expirience). And the strange is with that that SQL is case insensitive.

However just as far as I know.

Cor

Jul 21 '05 #10
Sorry, I had been silly in my editing. The actual field name was
"EntityName"--which is what I was using on the .NET side as well...

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
John,

Always the same problem and than I forgot it. You cannot use reserved SQL
words as items and AFAIK is "Name" one of them.

Cor

Jul 21 '05 #11
My database is VFP, so I don't have the sp_help option. In VFP, object
names are always case-insensitive. I suppose it's possible that MSSQL could
cause a variation depending on how it's sensitivity was configured, but I'm
still thinking it's based on .NET's handling of the stream it gets from the
database--whatever flavor that may be.

It is a bit funny to me that a typed data set doesn't have to match case,
but the rest of it seems to.

Is it C#, perhaps? I just don't remember, but I was thinking that VB is
less rabid about its case handling.

- John

Oh and just to be clear, it is a WinForm I'm working on.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Hmm.

I too was confused about winform and webform. :)

I thought you were onto something with the reserved word thing.
And the strange is with that that SQL is case insensitive.
"In SQL Server, object names can be case-sensitive, depending on the
character sort order that is installed. The sort order is chosen in SQL
Server Setup during installation. The default sort order in SQL Server
is dictionary order, case-insensitive.

If you need to change sort orders after installation, you must rebuild
your databases and reload your data."

John, try typing "execute sp_helpsort "in Query Analyzer to see what the
sort order and case-sensitivity is of your server. I know I am curious.

:)
Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Greg,

I saw that afterwards the same as you, that it could not be a webform
because that the dropdownlist has not a displaymember.

However than had John already sent a message replying you, I replied that and after that he came with the answer that is was a case situation.

However I am still not sure if it was the case situation here or the wrong itemname.

However the "case" is important in this situation (I have seen this to
often in this newsgroup while it is as well my own expirience). And the
strange is with that that SQL is case insensitive.

However just as far as I know.

Cor


Jul 21 '05 #12
I think you are right about it not mattering once you get it from the
database. It will matter if and when you try and write it back (if the
server is case-sensitive).

But... by not mattering I mean case-insensitive. Datatables etc are not
case-sensitive. Plus I just tried it to be sure! :)

Greg
"John Spiegel" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm pretty certain it was the case. The name, otherwise, DID match the
database.

I suppose the case sensitvity makes sense regardless of SQL's view since
once we get it from the database, it's no longer got anything to do with
SQL
and is instead up to .NET's interpretation.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Greg,

I saw that afterwards the same as you, that it could not be a webform
because that the dropdownlist has not a displaymember.

However than had John already sent a message replying you, I replied that
and after that he came with the answer that is was a case situation.

However I am still not sure if it was the case situation here or the
wrong
itemname.

However the "case" is important in this situation (I have seen this to

often
in this newsgroup while it is as well my own expirience). And the strange

is
with that that SQL is case insensitive.

However just as far as I know.

Cor


Jul 21 '05 #13
> My database is VFP

:)

I been making too many assumptions. Sorry.

I would think a typed dataset in C# would definately be case sensitive, and
not so in VB. Afterall, a typed dataset is just a class. But I am not sure
how the rules apply when it comes to setting DisplayMember properites, etc.

Greg

"John Spiegel" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
My database is VFP, so I don't have the sp_help option. In VFP, object
names are always case-insensitive. I suppose it's possible that MSSQL
could
cause a variation depending on how it's sensitivity was configured, but
I'm
still thinking it's based on .NET's handling of the stream it gets from
the
database--whatever flavor that may be.

It is a bit funny to me that a typed data set doesn't have to match case,
but the rest of it seems to.

Is it C#, perhaps? I just don't remember, but I was thinking that VB is
less rabid about its case handling.

- John

Oh and just to be clear, it is a WinForm I'm working on.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Hmm.

I too was confused about winform and webform. :)

I thought you were onto something with the reserved word thing.
>And the strange is with that that SQL is case insensitive.


"In SQL Server, object names can be case-sensitive, depending on the
character sort order that is installed. The sort order is chosen in SQL
Server Setup during installation. The default sort order in SQL Server
is dictionary order, case-insensitive.

If you need to change sort orders after installation, you must rebuild
your databases and reload your data."

John, try typing "execute sp_helpsort "in Query Analyzer to see what the
sort order and case-sensitivity is of your server. I know I am curious.

:)

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
> Greg,
>
> I saw that afterwards the same as you, that it could not be a webform
> because that the dropdownlist has not a displaymember.
>
> However than had John already sent a message replying you, I replied that > and after that he came with the answer that is was a case situation.
>
> However I am still not sure if it was the case situation here or the wrong > itemname.
>
> However the "case" is important in this situation (I have seen this to
> often in this newsgroup while it is as well my own expirience). And the
> strange is with that that SQL is case insensitive.
>
> However just as far as I know.
>
> Cor
>
>



Jul 21 '05 #14
Greg,

I tried that than as you probably almost suspected of course as well.

\\\only two comboboxes on a form.
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Greg")
For i As Integer = 0 To 9
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
ComboBox1.DataSource = dt
ComboBox2.DataSource = dt
ComboBox1.DisplayMember = "Greg"
ComboBox1.DisplayMember = "greg"
End Sub
///
Combobox1 shows a table from zero to 9
Combobox2 shows a for me a table with 10 times
System.Data.DataRowView

Can you try it as well to see if we have different systems?

Cor
"Greg Burns"
Jul 21 '05 #15
Greg,

Of course with a forgotten

:-)

Cor
Jul 21 '05 #16
My jaw has just hit the floor. You are (again) correct Cor.

I am seeing the same results, even when pulling from SQL (code below).

(My previous test was not actually using databinding afterall, sorry about
that)

It does appear to be case sensitive after reaching the datatable!

Since I have NEVER seen this before, I assume this is only case sensitive
when using DisplayMember and ValueMember??? (I rarely use databinding,
don't get me started) Accessing column data from the rows collection is not
case sensitive, is it?

I have never ran into this with webforms either and I use databinding with
DataTextField and DataValueField all the time. Do the same case-sensitivity
rules apply???

Greg
Dim cn As New SqlConnection("data source=.;initial
catalog=northwind;integrated security=SSPI;persist security
info=False;packet size=4096;")

'Dim cmd As New SqlCommand("SELECT CompanyName FROM shippers", cn)
Dim cmd As New SqlCommand("SELECT companyname FROM shippers", cn)
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)

da.Fill(dt)

ComboBox1.DataSource = dt
ComboBox2.DataSource = dt
ComboBox1.DisplayMember = "CompanyName"
ComboBox2.DisplayMember = "companyname"

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Greg,

I tried that than as you probably almost suspected of course as well.

\\\only two comboboxes on a form.
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Greg")
For i As Integer = 0 To 9
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
ComboBox1.DataSource = dt
ComboBox2.DataSource = dt
ComboBox1.DisplayMember = "Greg"
ComboBox1.DisplayMember = "greg"
End Sub
///
Combobox1 shows a table from zero to 9
Combobox2 shows a for me a table with 10 times
System.Data.DataRowView

Can you try it as well to see if we have different systems?

Cor
"Greg Burns"

Jul 21 '05 #17
Greg,
I have never ran into this with webforms either and I use databinding with
DataTextField and DataValueField all the time. Do the same
case-sensitivity rules apply???


You mean this one.
textbox1.DataBindings.Add(New Binding("Text", dataset1.Tables(0),
"LastName"))

Without testing now and AFAIK, Yes

Cor


Jul 21 '05 #18
> You mean this one.
textbox1.DataBindings.Add(New Binding("Text", dataset1.Tables(0),
"LastName"))
Nah, I mean binding a DropDownList in a webform...

ddlWeek.DataSource = eTime.ApproveWeeksDB.GetApproveWeeks
ddlWeek.DataTextField = "range" ' works either way "range" or "Range" or
"rAnGe"
ddlWeek.DataValueField = "WeekEnd"
ddlWeek.DataBind()

Does not seems to be case sensitive at all here. I am sure it is probably
an entirely different architecture behind the scenes (winform databinding
versus webform databinding). Well, at least as far as binding a web
DropDownList compared to a winform ComboBox goes.

Greg
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uZ**************@TK2MSFTNGP14.phx.gbl... Greg,
I have never ran into this with webforms either and I use databinding
with DataTextField and DataValueField all the time. Do the same
case-sensitivity rules apply???


You mean this one.
textbox1.DataBindings.Add(New Binding("Text", dataset1.Tables(0),
"LastName"))

Without testing now and AFAIK, Yes

Cor

Jul 21 '05 #19
Greg,

I try it probably tomorrow.

I have only to copy the code for that

:-)

OK?

Cor
Jul 21 '05 #20
Greg,

You are right as well about the webpage, I tested it, I saw there was a
little error in my windowform sample that you corrected in your test.
Therefore I show both samples now.

The Windowform sample in VBNet which "has to" be case sensitive and
therefore goes wrong and a webform sample in C# which maybe case insensitive
and therefore goes right.
\\\VBNet case sensitive windowform needs 2 comboboxes on a form
Private Sub Form11_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Greg")
For i As Integer = 0 To 9
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
ComboBox1.DataSource = dt
ComboBox2.DataSource = dt
ComboBox1.DisplayMember = "Greg"
ComboBox2.DisplayMember = "greg"
End Sub
///
\\\Case insensitive C# needs 2 dropdownlists on a form
private void Page_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Greg");
for (int i = 0; i < 10;i++)
{
DataRow dr = dt.NewRow();
dr[0] = i.ToString();
dt.Rows.Add(dr);
}
DropDownList1.DataSource = dt;
DropDownList2.DataSource = dt;
DropDownList1.DataTextField = "Greg";
DropDownList2.DataTextField = "greg";
DropDownList1.DataBind();
DropDownList2.DataBind();
}
///

Real weird is it not?

Cor
Jul 21 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alvaro E. Gonzalez V. | last post by:
Hello!!! I'm building a control that in a property assign a Dataset which they are initialized and another property Like DataMember. Similar as it happens to the DataSource property of a...
8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
0
by: Pietje puk | last post by:
Hello, Since im quite new to ASP.NET i wanted to ask you folks what the best way is to create a WebForm for modifying 1 field from a record. The manipulation of this field can be done by using...
20
by: John Spiegel | last post by:
Hi all, I think I've stared at it until it's made me stupid(er?). What am I missing about setting the list of the dropdown to display data pulled from a table? //......
1
by: Chris | last post by:
Hi, I have a button on a form, that opens a second form where I'm cloning a usercontrol, something akin to Access' continuous forms. Now, in this usercontrol I have a couple comboboxes. Now I...
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.