473,385 Members | 1,855 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.

How to set datasource for two comboboxes on the same form, from two columns of a tabl

I have designed a Windows form application with two comboboxes. I want combobox1 to take its contents from a column named "Type" in table "BIn" and combobox2 to take its contents from a column named "PN" in table "BIn". I already solved the case of a single input.but this is double input.I can't seem to be able to successfully extend the single input solution.

Here's what I've tried:

public B()
{
InitializeComponent();

SqlConnection con = new SqlConnection("Data Source=PV10\\LOCALSERVER;Initial Catalog=SmallSoftwareDB;Integrated Security=True;Pooling=False");
con.Open();
string sPn = "select PN from BIn";
string sTp = "select Type from BIn";
SqlCommand CsPn = new SqlCommand(sPn, con);
SqlCommand CsTp = new SqlCommand(sTp, con);

SqlDataReader mDr;
SqlDataReader CmDr;
mDr = CsPn.ExecuteReader();

while (mDr.Read())
{
comboBox2.Items.Add(mDr["PN"].ToString());
}

using (SqlDataAdapter da = new SqlDataAdapter(CsTp))
{
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "Type";
}
}
Sep 20 '16 #1
0 1470

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bart plessers | last post by:
Hello, I have a form with some checkboxes, i.e. The default value of this checkbox is determined in a global file (config.asp), that is included in first line of the form, i.e. ShowFilenames...
13
by: DraguVaso | last post by:
Hi, I need a function that gives me the number of Columns shown in a DataGrid. So I don't need to know the number of columns shown in tha DataSource, because this number can be completely...
2
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
2
by: Georg Schmelzer | last post by:
Hi Ng, I've got the following Problem: There is a windows form with one Datagrid. I set the datasource at runtime either to a at runtime designed datatable with for Columns, or to a also at...
4
by: pmclinn | last post by:
Below is the code I'm using to dynamically fill a datagrid from a datatable (fed by an ole connection). Everything is working great except that my users have to click 2 time on the checkbox to...
1
by: myname | last post by:
Hello, I assign a Datatable to a Datagrid.DataSource. All the columns are displayed with the same width. I would like them to be set automatically to the best width (something like Autofit...
0
by: anureddy | last post by:
help me how to add datagridview columns to another table,using windowsapplications. and set the displaymember and value member datagridviewcomboboxcolumn. i used this below code but that not...
2
by: Claudia Fong | last post by:
Hi, How can I create a grid of 20 Columns by 30 Rows using asp.net? Cheers! Claudi *** Sent via Developersdex http://www.developersdex.com ***
0
parshupooja
by: parshupooja | last post by:
Hi All, I have datasource returning 3 columns and various row: OperationTypeID,OperationType and OperationCode . This datasource is binded to Dropdownlist like this: ...
1
by: Tony Johansson | last post by:
Hello! In the Data Source Configuration Wizard I can choose Object as a Data source. It feel much more natural to have Database as the Data source. I feel very uncertain about having Object...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.