473,385 Members | 1,331 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,385 software developers and data experts.

problem binding comboBox to dataset

When I try to databind my comboBox (specifically field "emplcode") to a
filled dataset , the contents of the comboBox displays a bunch of
"System.Data.DataRowView". I assume the amount of times
"System.Data.DataR..." is displayed inside the combobox is the amount of
records in the dataset. On the other hand, if my query is "select emplcode
from payemployee", the databind will work fine (but I don't want to limit
the dataset to one field). Any help is appreciated. This is the code:

DataSet DS_Employees = new DataSet();

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated
Security=SSPI;" +

"Initial Catalog=payroll");

string strThisQuery = "select * from payemployee"; //If the query were
"select emplcode from payemployee" it works

SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);

DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter?

SQLConn.Close();

comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];

comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
comboBox_emplcode.DisplayMember = "payemployee.emplcode";

Thanks again,

Omar
Nov 15 '05 #1
6 7460
Set your DataValueField (i.e what the value should be if the combo box
is taking part in any events) and the DataTextField (what should be
displayed)..

try setting

comboBox_emplcode.DataTextField = " " <-- field u want as the display
comboBox_emplcode.DataValueField = " " <-- field u want as value..

also make sure u comboBox_emplcode.DataBind()
Omar wrote:
When I try to databind my comboBox (specifically field "emplcode") to a
filled dataset , the contents of the comboBox displays a bunch of
"System.Data.DataRowView". I assume the amount of times
"System.Data.DataR..." is displayed inside the combobox is the amount of
records in the dataset. On the other hand, if my query is "select emplcode
from payemployee", the databind will work fine (but I don't want to limit
the dataset to one field). Any help is appreciated. This is the code:

DataSet DS_Employees = new DataSet();

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated
Security=SSPI;" +

"Initial Catalog=payroll");

string strThisQuery = "select * from payemployee"; //If the query were
"select emplcode from payemployee" it works

SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);

DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter?

SQLConn.Close();

comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];

comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
comboBox_emplcode.DisplayMember = "payemployee.emplcode";

Thanks again,

Omar


Nov 15 '05 #2

Hello Omar,

You can do something like this:
try
{
DataSet ds=new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
adapter.Fill(ds);
comboBox1.DataSource=ds.Tables[0];
comboBox1.DisplayMember="job_desc";
comboBox1.ValueMember="job_id";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}

I use the default database of SqlServer and use the job_desc column as the
display item of comboBox, job_id column as the value item of the comboBox.
You can get the current selected member of these 2 column value by
comboBox1.SelectedText and comboBox1.SelectedValue.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar" <none>
| From: "Omar" <none>
| Subject: problem binding comboBox to dataset
| Date: Wed, 8 Oct 2003 17:51:35 -0500
| Lines: 36
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uX**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 66-50-71-153.prtc.net 66.50.71.153
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190027
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| When I try to databind my comboBox (specifically field "emplcode") to a
| filled dataset , the contents of the comboBox displays a bunch of
| "System.Data.DataRowView". I assume the amount of times
| "System.Data.DataR..." is displayed inside the combobox is the amount of
| records in the dataset. On the other hand, if my query is "select emplcode
| from payemployee", the databind will work fine (but I don't want to limit
| the dataset to one field). Any help is appreciated. This is the code:
|
| DataSet DS_Employees = new DataSet();
|
| SqlConnection SQLConn = new SqlConnection("Data Source=localhost;
Integrated
| Security=SSPI;" +
|
| "Initial Catalog=payroll");
|
| string strThisQuery = "select * from payemployee"; //If the query were
| "select emplcode from payemployee" it works
|
| SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);
|
| DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter?
|
| SQLConn.Close();
|
| comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];
|
| comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
| comboBox_emplcode.DisplayMember = "payemployee.emplcode";
|
|
|
| Thanks again,
|
| Omar
|
|
|

Nov 15 '05 #3
Thanks for the response.
In my case, the DataTextField or DataValueField members don't exist and the
DataBind method doesn't exist either.

"Kunal" <ku***@nospamsoremovethisqnal.net> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...
Set your DataValueField (i.e what the value should be if the combo box
is taking part in any events) and the DataTextField (what should be
displayed)..

try setting

comboBox_emplcode.DataTextField = " " <-- field u want as the display
comboBox_emplcode.DataValueField = " " <-- field u want as value..

also make sure u comboBox_emplcode.DataBind()
Omar wrote:
When I try to databind my comboBox (specifically field "emplcode") to a
filled dataset , the contents of the comboBox displays a bunch of
"System.Data.DataRowView". I assume the amount of times
"System.Data.DataR..." is displayed inside the combobox is the amount of
records in the dataset. On the other hand, if my query is "select emplcode from payemployee", the databind will work fine (but I don't want to limit the dataset to one field). Any help is appreciated. This is the code:

DataSet DS_Employees = new DataSet();

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" +

"Initial Catalog=payroll");

string strThisQuery = "select * from payemployee"; //If the query were
"select emplcode from payemployee" it works

SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);

DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter?
SQLConn.Close();

comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];

comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
comboBox_emplcode.DisplayMember = "payemployee.emplcode";

Thanks again,

Omar


Nov 15 '05 #4
Thanks for your post. I tried it your way with the same result. Instead of
displaying 111 emplcodes (the amount of records in the table), it displays
111 "System.Data.DataRowView". I *did* notice that it ignores the
comboBox.DisplayMember member.

I also tried it like this:
try
{
DataSet DS_Employees=new DataSet();
SqlConnection SQLConn = new SqlConnection("Data Source=localhost;
Integrated Security=SSPI;" +
"Initial Catalog=payroll");
SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);
DA_empl.Fill(DS_Employees, "payemployee");
SQLConn.Close();
DataView dv = new DataView(DS_Employees.Tables["Payemployee"]);
comboBox1.DataSource=dv;
comboBox1.DisplayMember = "FName";
// I can susbstitute the previous line with comboBox1.DisplayMember =
"thisFieldDoesntExist"; and it'll display the same 111
"System.Data.DataR..." lines
catch(Exception ex)
{
MessageBox.Show(ex.Message ); //it never displays the MessageBox since
it never encounters an error.
}

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:jC**************@cpmsftngxa06.phx.gbl...

Hello Omar,

You can do something like this:
try
{
DataSet ds=new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
adapter.Fill(ds);
comboBox1.DataSource=ds.Tables[0];
comboBox1.DisplayMember="job_desc";
comboBox1.ValueMember="job_id";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}

I use the default database of SqlServer and use the job_desc column as the
display item of comboBox, job_id column as the value item of the comboBox.
You can get the current selected member of these 2 column value by
comboBox1.SelectedText and comboBox1.SelectedValue.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar" <none>
| From: "Omar" <none>
| Subject: problem binding comboBox to dataset
| Date: Wed, 8 Oct 2003 17:51:35 -0500
| Lines: 36
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uX**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 66-50-71-153.prtc.net 66.50.71.153
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190027 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| When I try to databind my comboBox (specifically field "emplcode") to a
| filled dataset , the contents of the comboBox displays a bunch of
| "System.Data.DataRowView". I assume the amount of times
| "System.Data.DataR..." is displayed inside the combobox is the amount of
| records in the dataset. On the other hand, if my query is "select emplcode | from payemployee", the databind will work fine (but I don't want to limit | the dataset to one field). Any help is appreciated. This is the code:
|
| DataSet DS_Employees = new DataSet();
|
| SqlConnection SQLConn = new SqlConnection("Data Source=localhost;
Integrated
| Security=SSPI;" +
|
| "Initial Catalog=payroll");
|
| string strThisQuery = "select * from payemployee"; //If the query were
| "select emplcode from payemployee" it works
|
| SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);
|
| DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter? |
| SQLConn.Close();
|
| comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];
|
| comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
| comboBox_emplcode.DisplayMember = "payemployee.emplcode";
|
|
|
| Thanks again,
|
| Omar
|
|
|


Nov 15 '05 #5
I finally found the answer. Apparently, the field in
comboBox.DisplayMember is case-sensitive (at least for SQL Server 2000).
The funny thing is that the sql statement used to fill the dataset is *not*
case-sensitive.

Thanks again for the help.
"Omar" <none> wrote in message news:uX**************@tk2msftngp13.phx.gbl...
When I try to databind my comboBox (specifically field "emplcode") to a
filled dataset , the contents of the comboBox displays a bunch of
"System.Data.DataRowView". I assume the amount of times
"System.Data.DataR..." is displayed inside the combobox is the amount of
records in the dataset. On the other hand, if my query is "select emplcode
from payemployee", the databind will work fine (but I don't want to limit
the dataset to one field). Any help is appreciated. This is the code:

DataSet DS_Employees = new DataSet();

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" +

"Initial Catalog=payroll");

string strThisQuery = "select * from payemployee"; //If the query were
"select emplcode from payemployee" it works

SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);

DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd parameter?

SQLConn.Close();

comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];

comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
comboBox_emplcode.DisplayMember = "payemployee.emplcode";

Thanks again,

Omar

Nov 15 '05 #6

Hi Omar,

I think the SQL statement is passed to the SqlServer by the .Net
application, and it will be handled by the SqlServer, so it is not
case-sensitive.
While binding the ComboBox's DisplayMember property with certain field of
database, this field is already the column of DataSet and it is processed
in .Net, so it is case-sensitive.(I think this is determined by the design
of DisplayMember property).

I am glad you finally found the problem, I think we all must be careful of
this type of problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar" <none>
| From: "Omar" <none>
| References: <uX**************@tk2msftngp13.phx.gbl>
| Subject: Re: problem binding comboBox to dataset
| Date: Thu, 9 Oct 2003 12:16:35 -0500
| Lines: 48
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#U**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 66-50-71-48.prtc.net 66.50.71.48
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190286
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I finally found the answer. Apparently, the field in
| comboBox.DisplayMember is case-sensitive (at least for SQL Server 2000).
| The funny thing is that the sql statement used to fill the dataset is
*not*
| case-sensitive.
|
| Thanks again for the help.
|
|
| "Omar" <none> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...
| > When I try to databind my comboBox (specifically field "emplcode") to a
| > filled dataset , the contents of the comboBox displays a bunch of
| > "System.Data.DataRowView". I assume the amount of times
| > "System.Data.DataR..." is displayed inside the combobox is the amount of
| > records in the dataset. On the other hand, if my query is "select
emplcode
| > from payemployee", the databind will work fine (but I don't want to
limit
| > the dataset to one field). Any help is appreciated. This is the code:
| >
| > DataSet DS_Employees = new DataSet();
| >
| > SqlConnection SQLConn = new SqlConnection("Data Source=localhost;
| Integrated
| > Security=SSPI;" +
| >
| > "Initial Catalog=payroll");
| >
| > string strThisQuery = "select * from payemployee"; //If the query were
| > "select emplcode from payemployee" it works
| >
| > SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);
| >
| > DA_empl.Fill(DS_Employees, "payemployee"); //Do I need the 2nd
parameter?
| >
| > SQLConn.Close();
| >
| > comboBox_emplcode.DataSource = DS_Employees.Tables["payemployee"];
| >
| > comboBox_emplcode.DisplayMember = "emplcode"; //I also tried
| > comboBox_emplcode.DisplayMember = "payemployee.emplcode";
| >
| >
| >
| > Thanks again,
| >
| > Omar
| >
| >
|
|
|

Nov 15 '05 #7

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

Similar topics

13
by: Paul Slavin | last post by:
I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this?? any answers appreciated, as to due to the underlying...
3
by: Russ | last post by:
I have a subroutine that I call to bind a dataset to a combobox. It works sometimes. See the code below.. 1 Private Sub BindDropDownToDataSet( _ 2 ByRef control As...
5
by: Poonam | last post by:
I have a department table with DeptID and DeptName. I am trying to fill my combobox with DeptName. Here is my code but it does not work? Can someone help me? Dim pxy As New Channel1.Channel...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
0
by: Tommaso Caldarola | last post by:
2.0 - No Typed DataSet. My custom object implements all the needed interface (IList, IBindingList, ITypedList) in order to manage complex binding. With DataGridView control I have no problem. ...
3
by: Peter | last post by:
OK, so in addition to the problem I mentioned before (c.f. "Data Binding to Textbox"), I realized that my comboboxes are not really bound to the internal data set. They are just set to manually...
1
by: Robert Dufour | last post by:
I have a table of addresses and it contains a CountryId which points to a table of countries. The datatstructure of the Countries Lookup tables is actually created from three tables - a...
1
by: Jim | last post by:
Hi, Trying to implement databinding. I've a dataset with a table, a windows form with typical controls: combobox, datetimepicker, textbox . . . I use what I think is a normal method to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.