Hi there,
I'm new to C#, and I have a small problem.
I have created a new DataSet using the code below, and I would like to
be able to populat a drop-down list with the results of the "name"
field. Can anyone help me, please?
*************** *************** *************** ****
string m_Connect = "Data Source=(local); integrated
security=SSPI;I nitial Catalog=databas e_name;";
SqlConnection myConn = new SqlConnection(m _Connect);
SqlDataAdapter da = new SqlDataAdapter( );
myConn.Open();
DataSet ds1 = new DataSet();
string sQueryString1 = "";
sQueryString1 = "SELECT * FROM sysobjects where type='U'";
da.SelectComman d = new SqlCommand(sQue ryString1,myCon n);
da.Fill(ds1, "ImportTabl e");
*************** *************** *************** ****
Thanks,
Marc. 4 14647
comboBox1.DataS ource = ds1;
comboBox1.Displ ayMember = "Whatever2S ee";
comboBox1.Value Member = "Whatever2Have" ;
Then to bound the combobox to the SelectedValue property using the DataTable
in ds1:
comboBox1.DataB indings.Add("Se lectedValue", this.ds1.Tables[0],
"Whatever2Have" );
Hope it helps
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Marc Jennings" <marc.nospam..j e******@gmail.c om> wrote in message
news:48******** *************** *********@4ax.c om... Hi there,
I'm new to C#, and I have a small problem.
I have created a new DataSet using the code below, and I would like to be able to populat a drop-down list with the results of the "name" field. Can anyone help me, please?
*************** *************** *************** ****
string m_Connect = "Data Source=(local); integrated security=SSPI;I nitial Catalog=databas e_name;"; SqlConnection myConn = new SqlConnection(m _Connect); SqlDataAdapter da = new SqlDataAdapter( ); myConn.Open(); DataSet ds1 = new DataSet(); string sQueryString1 = ""; sQueryString1 = "SELECT * FROM sysobjects where type='U'"; da.SelectComman d = new SqlCommand(sQue ryString1,myCon n); da.Fill(ds1, "ImportTabl e");
*************** *************** *************** ****
Thanks, Marc.
Thanks for the quick reply...
If I understood you correctly, if I want to fill the combobox (called
tableslist) with the names of the tables, I should use the following
code....
tableslist.Data Source = ds1;
tableslist.Disp layMember = "name";
tableslist.Valu eMember = "name";
tableslist.Data Bindings.Add("S electedValue", ds1.Tables[0],"name");
It is a very simnple app to export the contents of a given table to
XML, so all the data retrieval happens in the same function - hence
the lack of "this."
I have tried the code above and it doesn't populate the list, so I
have to assume I have misunderstood what you meant.
On Thu, 1 Jul 2004 17:17:55 +0300, "Tamir Khason"
<ta**********@t con-NOSPAM.co.il> wrote: comboBox1.Data Source = ds1; comboBox1.Disp layMember = "Whatever2S ee"; comboBox1.Valu eMember = "Whatever2Have" ;
Then to bound the combobox to the SelectedValue property using the DataTable in ds1:
comboBox1.Data Bindings.Add("S electedValue", this.ds1.Tables[0], "Whatever2Have ");
Hope it helps
If your select return something like:
name id surname age
john 1 Dow 30
john 2 Brown 34
ann 3 Fox 21
by using this: tableslist.Data Source = ds1; tableslist.Disp layMember = "name"; tableslist.Valu eMember = "name";
you should recieve combobox of 3 items named john,john and ann with the same
values
while you select one of items and onSelectionChan ge writes age in other
textbox by using this:tableslist.Dat aBindings.Add(" SelectedValue", ds1.Tables[0],"name");
You will see 21 while select third item
This works fine for me
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Marc Jennings" <marc.nospam..j e******@gmail.c om> wrote in message
news:e6******** *************** *********@4ax.c om... Thanks for the quick reply...
If I understood you correctly, if I want to fill the combobox (called tableslist) with the names of the tables, I should use the following code....
tableslist.Data Source = ds1; tableslist.Disp layMember = "name"; tableslist.Valu eMember = "name"; tableslist.Data Bindings.Add("S electedValue", ds1.Tables[0],"name");
It is a very simnple app to export the contents of a given table to XML, so all the data retrieval happens in the same function - hence the lack of "this."
I have tried the code above and it doesn't populate the list, so I have to assume I have misunderstood what you meant.
On Thu, 1 Jul 2004 17:17:55 +0300, "Tamir Khason" <ta**********@t con-NOSPAM.co.il> wrote:
comboBox1.Data Source = ds1; comboBox1.Disp layMember = "Whatever2S ee"; comboBox1.Valu eMember = "Whatever2Have" ;
Then to bound the combobox to the SelectedValue property using the
DataTablein ds1:
comboBox1.Data Bindings.Add("S electedValue", this.ds1.Tables[0], "Whatever2Have ");
Hope it helps
Thanks again. I found out where it was all going wrong for me. I had
followed the instruction literally, and not thought to change the
DataSource from ds1 to ds1.Tables[0]
I can't believe I spent so long chasing my tail looking for this
simple answer!!!!
Thanks again.
Marc.
On Thu, 1 Jul 2004 17:43:28 +0300, "Tamir Khason"
<ta**********@t con-NOSPAM.co.il> wrote: If your select return something like: name id surname age john 1 Dow 30 john 2 Brown 34 ann 3 Fox 21
by using this: tableslist.Data Source = ds1; tableslist.Disp layMember = "name"; tableslist.Valu eMember = "name"; you should recieve combobox of 3 items named john,john and ann with the same values while you select one of items and onSelectionChan ge writes age in other textbox by using this:tableslist.Da taBindings.Add( "SelectedValue" , ds1.Tables[0],"name"); You will see 21 while select third item
This works fine for me This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Goldsworth_Systems |
last post by:
I have a string containing valid XML.
How do I populate a dataset based on the string, without reference to an XML
schema or writing the XML to file and reading it back in again?
|
by: Jassim Rahma |
last post by:
Hi,
what is the best way to populate comboBox from database.. the reason I
am asking is that i have more than 8 comboBoxes in one form and each
should retrieve data from a table and I don't want that to slow the form
show.
can you please submit a sample code...
|
by: Sharon |
last post by:
I have successfully loaded a DataSet object with a XML schema (XSD).
Now I wish to populate the tables that was created in the DataSet.
I have an XML file/string that contain all the needed data in the same
format as the XSD (the XML file/string was created using this same schema).
The XML file/string may contain data for a single table or for several
tables at once.
The question is:
|
by: Paul D. Fox |
last post by:
I would like to read from Active Directory and populate a dataset to be
passed in a Web Service. I can get the data from AD just fine, but can I
populate a dataset with these values and do a "Return dataSetName" in my web
service?
|
by: Sachin |
last post by:
Hi,
I am working on ASP.Net 2.0 Beta 2
I am having problems creating crystal report using dataset
I created a new dataset (DS_ExpCode) and a datatable (DT_ExpCode) under
App_Code folder.
Then i create a new crystal report
A Standard Report Creation Wizard window popus up with available datasource
I selected Project Data -> ADO.Net Dataset, i see the dataset recently
| |
by: paumierj |
last post by:
Hi there
Here's my question :
I'd like to populate a dataset from an XML string, ie:
Dim sXmlString As String
sXmlString = "<root type='E-Form'><question label='This is my first
question'></question><question label='This is my second
question'></question></root>
|
by: John |
last post by:
Hi all,
I'm sorry I'm reposting this but the original was urgent and I do need
closure on this.
I'm calling a stored proc which does 4 "selects" and then I populate a
dataset looping through the dr using a dr.NextResult() but the stored proc
may not return any results for one or more Select stetments. When this
happens, a table is not returned so the dataset.Fill() does not populate
conatin 4 tables which then each bind to a grid -...
|
by: vnaz235 |
last post by:
Hi, guys,
1. Can anybody help me to populate ComboBox on VB6 form with
a) text strings from the range on the already existing Excel sheet (e.g., Workbook("Test1").Sheets("Sheet1").Range("P12:P72")) and another ComboBox with
b) names of visible Excel sheets in the same workbook?
2. How to pass selected items from ComboBox1 into Workbook("Test1").Sheets("Sheet1").Range("A1") and from ComboBox2 into...
|
by: freekedoutfish |
last post by:
Hi. New member here
Im sat at work, pounding my head off the desk because this tiny bit of simple code refuses to work.
The sub is intended to pull data from the "companyname" column in the "cmSelectAllCompanyNames" table, and put all the company names it finds into the "cbFilterCompanyName" combo box.
Now the confusing aspect is this:
It works!!!
|
by: =?Utf-8?B?Q2hyaXM=?= |
last post by:
This actually stemmed from anther post I created.
But, I have two combo boxes. ComboBox1 is populated by a list of Systems
(DataSet from Oracle Query).
Now, I want to take Combobox2, and when the data is changed on Combox1, I
want to populate data depending on the selection in Combox1.
So, ComboBox1 lists "OracleDB123". I want ComboBox2 to list all accounts on
that system. That information is stored in say the Accounts
|
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...
| |
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: 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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |