Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2011, 07:34 AM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with combobox data binding in window application

Hi all,

I am new in window application in C#. Currently I want to bind the selected SQL data into a combobox. I want to display only the Office name and the officeid will be the value for individual officename.
Here is my code and store procedure below:-

Code:-
__________
string con = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(con);
SqlCommand command = new SqlCommand("Office_Select", conn);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "User");

cmb_Office.DataSource = ds;
cmb_Office.DisplayMember = "OfficeName";
cmb_Office.ValueMember = "ds.OfficeID";
cmb_Office.DataBindings();

Store procedure:-
____________
Create PROCEDURE [dbo].[Office_Select]

AS
BEGIN
select OfficeName,OfficeID from User_Login
END

In case of Web Application this methode works well. I do not know why it is not working at all.
Please some one help me in this context.

With regards
Somesh Chatterjee
 
Old May 23rd, 2011, 07:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If this is about a Windows application, I think you're better off posting this in a Win Forms forum, not an ASP.NET forum. If I were you, I'd find an appropriate category here: http://p2p.wrox.com/ and post your question there.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 23rd, 2011, 09:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

HI there.. once you move.. check this:

cmb_Office.ValueMember = "ds.OfficeID";

should be

cmb_Office.ValueMember = "OfficeID";
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old November 19th, 2012, 04:35 AM
Registered User
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default net grid

Each Windows Form has at least one BindingContext object that manages the CurrencyManager objects for the form. For each data source on a Windows Form, there is a single CurrencyManager object. Because there may be multiple data sources associated with a Windows Form, the BindingContext object enables you to retrieve any particular CurrencyManager object associated with a data source.
For example if you add a TextBox control to a form and bind it to a column of a table (e.g. "Customers.FirstName") in a dataset (e.g. "dsCust"), the control communicates with the BindingContext object for that form. The BindingContext object, in turn, talks to the specific CurrencyManager object for that data association. If you queried the CurrencyManager's Position property, it would report the current record for that TextBox control's binding. In the example below, a TextBox control is bound to the FirstName column of a Customers table on the dsCust dataset through the BindingContext object for the form it is on.

// Simple Data Binding
txtBox.DataBindings.Add("Text",dsCust,"Customers.F irstName");

// Get current Rowposition
CurrencyManager cm = (CurrencyManager)this.BindingContext[dsCust,"Customers"];
long rowPosition = (long)cm.Position;
dapfor. com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
data binding a combobox ozPATT Excel VBA 1 November 16th, 2005 08:17 AM
problem in binding data vijjum3 General .NET 1 December 29th, 2004 08:41 AM
ComboBox Data Binding bmains VB.NET 0 October 5th, 2004 02:35 PM
Data Binding Problem jbenson001 ASP.NET 1.x and 2.0 Application Design 3 December 18th, 2003 01:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.