473,657 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Da taRowView". I assume the amount of times
"System.Data.Da taR..." 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=localhos t; 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, "payemploye e"); //Do I need the 2nd parameter?

SQLConn.Close() ;

comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];

comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";

Thanks again,

Omar
Nov 15 '05 #1
6 7476
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_emplco de.DataTextFiel d = " " <-- field u want as the display
comboBox_emplco de.DataValueFie ld = " " <-- field u want as value..

also make sure u comboBox_emplco de.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.Da taRowView". I assume the amount of times
"System.Data.Da taR..." 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=localhos t; 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, "payemploye e"); //Do I need the 2nd parameter?

SQLConn.Close() ;

comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];

comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";

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=l ocalhost;databa se=pubs;uid=sa; pwd=");
adapter.Fill(ds );
comboBox1.DataS ource=ds.Tables[0];
comboBox1.Displ ayMember="job_d esc";
comboBox1.Value Member="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.Selec tedText and comboBox1.Selec tedValue.

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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 66-50-71-153.prtc.net 66.50.71.153
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1900 27
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.Da taRowView". I assume the amount of times
| "System.Data.Da taR..." 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=localhos t;
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, "payemploye e"); //Do I need the 2nd parameter?
|
| SQLConn.Close() ;
|
| comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];
|
| comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
| comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";
|
|
|
| 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***@nospamso removethisqnal. net> wrote in message
news:uw******** ******@TK2MSFTN GP09.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_emplco de.DataTextFiel d = " " <-- field u want as the display
comboBox_emplco de.DataValueFie ld = " " <-- field u want as value..

also make sure u comboBox_emplco de.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.Da taRowView". I assume the amount of times
"System.Data.Da taR..." 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=localhos t; 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, "payemploye e"); //Do I need the 2nd parameter?
SQLConn.Close() ;

comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];

comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";

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.Da taRowView". I *did* notice that it ignores the
comboBox.Displa yMember member.

I also tried it like this:
try
{
DataSet DS_Employees=ne w DataSet();
SqlConnection SQLConn = new SqlConnection(" Data Source=localhos t;
Integrated Security=SSPI;" +
"Initial Catalog=payroll ");
SqlDataAdapter DA_empl = new SqlDataAdapter (strThisQuery, SQLConn);
DA_empl.Fill(DS _Employees, "payemploye e");
SQLConn.Close() ;
DataView dv = new DataView(DS_Emp loyees.Tables["Payemploye e"]);
comboBox1.DataS ource=dv;
comboBox1.Displ ayMember = "FName";
// I can susbstitute the previous line with comboBox1.Displ ayMember =
"thisFieldDoesn tExist"; and it'll display the same 111
"System.Data.Da taR..." lines
catch(Exception ex)
{
MessageBox.Show (ex.Message ); //it never displays the MessageBox since
it never encounters an error.
}

"Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> wrote in message
news:jC******** ******@cpmsftng xa06.phx.gbl...

Hello Omar,

You can do something like this:
try
{
DataSet ds=new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter( "select * from
jobs","server=l ocalhost;databa se=pubs;uid=sa; pwd=");
adapter.Fill(ds );
comboBox1.DataS ource=ds.Tables[0];
comboBox1.Displ ayMember="job_d esc";
comboBox1.Value Member="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.Selec tedText and comboBox1.Selec tedValue.

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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 66-50-71-153.prtc.net 66.50.71.153
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1900 27 | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.Da taRowView". I assume the amount of times
| "System.Data.Da taR..." 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=localhos t;
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, "payemploye e"); //Do I need the 2nd parameter? |
| SQLConn.Close() ;
|
| comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];
|
| comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
| comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";
|
|
|
| Thanks again,
|
| Omar
|
|
|


Nov 15 '05 #5
I finally found the answer. Apparently, the field in
comboBox.Displa yMember 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******** ******@tk2msftn gp13.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.Da taRowView". I assume the amount of times
"System.Data.Da taR..." 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=localhos t; 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, "payemploye e"); //Do I need the 2nd parameter?

SQLConn.Close() ;

comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];

comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";

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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 66-50-71-48.prtc.net 66.50.71.48
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1902 86
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| I finally found the answer. Apparently, the field in
| comboBox.Displa yMember 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******** ******@tk2msftn gp13.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.Da taRowView". I assume the amount of times
| > "System.Data.Da taR..." 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=localhos t;
| 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, "payemploye e"); //Do I need the 2nd
parameter?
| >
| > SQLConn.Close() ;
| >
| > comboBox_emplco de.DataSource = DS_Employees.Ta bles["payemploye e"];
| >
| > comboBox_emplco de.DisplayMembe r = "emplcode"; //I also tried
| > comboBox_emplco de.DisplayMembe r = "payemployee.em plcode";
| >
| >
| >
| > 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
4300
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 structure of the datasets, i.e lots of child tables etc, I cannot use bindingcontext
3
1858
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 System.Windows.Forms.ComboBox, _ 3 ByVal ds As DataSet) 4 Try 5 control.DataSource = ds.Tables(0) 6 control.ValueMember = ds.Tables(0).Columns(0).ColumnName 7 control.DisplayMember =
5
6679
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 dsDepts = pxy.getDepartments() cmbDept.DisplayMember = "DeptName" cmbDept.ValueMember = "DeptID" cmbDept.DataSource = dsDepts.Tables("Department")
30
4567
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
0
2208
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 correctly, posting to the wrong forum, or committing some other sort of faux pas. My team is developing a Windows Forms application using VS 2005 with SQL Server 2005 on the back end and we're having a problem using ComboBoxes data bound to lookup...
0
1398
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. I have encountered problems when I try using data bound ComboBox, namely if I set combo.DataSource = OrderTypeCollection; (of OrderType class e.g.)
3
1644
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 change to reflect whatever the selected row's foreign keys are. So the question is, how can I bind the SelectedItem of a combobox, which is filled with DataRowView objects from its bound table, to a field in whichever row of a dataset happens to...
1
1762
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 CountryIdtable - a Countries localized tables and an cultures tables From which I extract a dataset select CountryID - CountryName - Culture name (with inner joins between the three) where CultureName = CurrentCulture.CurrentUiCulture.tostring. So I would...
1
2232
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 establish the bindings: textbox1.databindings.add("text", dataset, table.column) The records displays in the UI(if it exists). I can create an initial record and successfully save to the database.
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.