dear,
I have a form (frmlogonaccoun ts.cs) with a combobox, which I want to fill up
with the first column of a dataset. The dataset is created in the class
Login. My problem is the next : I make a new login in the form loginaccount
which create a new login and give me a dataset (created by class login),
which I can see in my datagrid. But I want to fill up my combobox with only
the name of the logon and I do this with an foreach. But when I see the
result the combobox is filled up with only the name of the column, not with
the data in the dataset (as I said I see the data in the datagrid: so the
dataset is filled up).
What do I wrong ? Below you find the code in class Login and class
frmlogonaccount
Thank you very much.
Hugo
code Login :
public Login(out DataSet ds)
{
SqlSelectie = "select * from Login; ";
Database db = new Database();
SqlConnection conn = db.Opent();
SqlCommand cmd = new SqlCommand(SqlS electie, conn);
SqlDataAdapter da = new SqlDataAdapter( SqlSelectie, conn);
ds = new DataSet();
da.Fill(ds, "Login");
conn.Close();
}
code frmlogonaccount :
DataSet ds = new DataSet("Login" );
Login SqlLogin = new Login(out ds);
dataGrid1.SetDa taBinding(ds, "Login");
///the next statement gives me the name of the column NOT the data
foreach (DataRow dr in ds.Tables["Login"].Rows)
cboListLogon.It ems.Add(dr.Tabl e.Columns[0]); 2 3464
Hi Hugo,
"Hugo Lefevre" <hu**********@t iscali.be> wrote in message
news:bu******** **@news.worldon line.be... dear,
I have a form (frmlogonaccoun ts.cs) with a combobox, which I want to fill
up with the first column of a dataset. The dataset is created in the class Login. My problem is the next : I make a new login in the form
loginaccount which create a new login and give me a dataset (created by class login), which I can see in my datagrid. But I want to fill up my combobox with
only the name of the logon and I do this with an foreach. But when I see the result the combobox is filled up with only the name of the column, not
with the data in the dataset (as I said I see the data in the datagrid: so the dataset is filled up).
What do I wrong ? Below you find the code in class Login and class frmlogonaccount
Thank you very much.
Hugo code Login :
public Login(out DataSet ds) { SqlSelectie = "select * from Login; "; Database db = new Database(); SqlConnection conn = db.Opent(); SqlCommand cmd = new SqlCommand(SqlS electie, conn); SqlDataAdapter da = new SqlDataAdapter( SqlSelectie, conn); ds = new DataSet(); da.Fill(ds, "Login"); conn.Close(); }
code frmlogonaccount :
DataSet ds = new DataSet("Login" ); Login SqlLogin = new Login(out ds); dataGrid1.SetDa taBinding(ds, "Login"); ///the next statement gives me the name of the column NOT the data foreach (DataRow dr in ds.Tables["Login"].Rows) cboListLogon.It ems.Add(dr.Tabl e.Columns[0]);
It should be:
cboListLogon.It ems.Add((string )dr[0]);
instead.
Also you might consider databinding to combobox entire table
ds.Tables["Login"].
Just set DisplayMember = "columnname " and DataSource = ds.Tables["Login"];
--
Miha Markic - RightHand .NET consulting & development
miha at rthand com www.rthand.com
Hi Hugo,
You can try databinding the login name column to your
combobox by using the DisplayMember and ValueMember
properties. Here's a code snippet:
cboListLogon.Da taSource=ds.Tab les["Login"];
cboListLogon.Di splayMember="lo ginname";
cboListLogon.Va lueMember="logi nname";
Regards,
Aravind C
"Hugo Lefevre" <hu**********@t iscali.be> wrote in message
news:bu******** **@news.worldon line.be... dear,
I have a form (frmlogonaccoun ts.cs) with a combobox, which I want to fill
up with the first column of a dataset. The dataset is created in the class Login. My problem is the next : I make a new login in the form
loginaccount which create a new login and give me a dataset (created by class login), which I can see in my datagrid. But I want to fill up my combobox with
only the name of the logon and I do this with an foreach. But when I see the result the combobox is filled up with only the name of the column, not
with the data in the dataset (as I said I see the data in the datagrid: so the dataset is filled up).
What do I wrong ? Below you find the code in class Login and class frmlogonaccount
Thank you very much.
Hugo code Login :
public Login(out DataSet ds) { SqlSelectie = "select * from Login; "; Database db = new Database(); SqlConnection conn = db.Opent(); SqlCommand cmd = new SqlCommand(SqlS electie, conn); SqlDataAdapter da = new SqlDataAdapter( SqlSelectie, conn); ds = new DataSet(); da.Fill(ds, "Login"); conn.Close(); }
code frmlogonaccount :
DataSet ds = new DataSet("Login" ); Login SqlLogin = new Login(out ds); dataGrid1.SetDa taBinding(ds, "Login"); ///the next statement gives me the name of the column NOT the data foreach (DataRow dr in ds.Tables["Login"].Rows) cboListLogon.It ems.Add(dr.Tabl e.Columns[0]);
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kaneda |
last post by:
Hello everyone!
I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.
I have a ComboBox I need to fill with the content of an untyped DataSet.
This is to be done in the "DropDown" Event (since the dataset is empty at
program start).
If I go with this:
|
by: -elniniol999- |
last post by:
I am DESPERATE for a quick reply.. have exhausted my options...
i have a table called order details which contains:
order id
product id
product name
quantity
unit price
sale price
|
by: reidarT |
last post by:
I am filling a combobox with data from a table.
This is done with the code below.
After update of the combobox I want to fill txtField2 with data from Field2
in the select-statement.
How can I do that?
private void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
|
by: reidarT |
last post by:
I have found a good combobox with multiple fields
The example shows filling the combobox from a listview, but I want to fill
it with zip-code and cities from a database.
The example is as follows:
Dim dtLoading As New DataTable("UsStates")
dtLoading.Columns.Add("Name", System.Type.GetType("System.String"))
dtLoading.Columns.Add("Abbreviation", System.Type.GetType("System.String"))
|
by: fstenoughsnoopy |
last post by:
I have a customer order database and I need to pull a customers
information, ie first name, last name, address, city, state, zip,
phone, etc, into the oder table. i don't know how to go about making
this work...
| |
by: kimtherkelsen |
last post by:
Hi,
I do this:
this.comboBox.DataSource =
myDataSet.Tables.Select("location_key = " +
selectedLocationKey);
this.comboBox.DisplayMember = "text";
this.comboBox.ValueMember = "subcustomer_location_key";
but get an exception when setting the value member. Unfortunately there
|
by: phytorion |
last post by:
idk why this is giving me such a problem but here it is. I need to add a combobox to a continuous form. This combobox needs to allow the user to select between "S" and "T" for each record in this recordset. I've tried to make it work selecting the values from a table and i've tried just having a valuelist in the combobox. both give me the same result when i run it, when you select a value it automatically selects that value for every...
|
by: sixths3ns3 |
last post by:
My DataGridView has two columns. Combobox Column 2 displays list based on Combobox Column 1 selected value. The code below works fine when I select a value on Column 1, and select a value on Column 2. But on the next row, when I leave Column 1 blank and click on Column 2, it generates error DataGridViewComboBoxCell value is invalid. And the code below works fine the first time I click Column 2, leaving Column 1 blank.
I just want to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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...
| |
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |