Hi folks, i wanted to know if there's a way i can save into a string array the values contained in a datatable.
Also, i know i can save into a combobox the values of a DataTable containing a SQL query from a Database, but is there a way i can get this values saved in the combobox, to save them in a string array?
Class1 Object1=new Class1();
this.combobox1.DataSource=Object1.MethodDataTable( );
8 1955
So, a String Array is just an array of a bunch of Strings.
A DataTable has rows and columns.
Therefore a DataTable cannot be saved into a 1 dimensional string array.
It doesn't make any sense to ask what you are asking.
Maybe you mean to save it into a 2D string array...why you would want to do something like that is beyond me because working with a DataTable has benefits over working with a 2D string array.
If you really want to do this you need to loop through all of the rows for the table...and for each row that you loop through you need to loop through all of the columns for that row in order to retrieve what is in the specific cell.
The ComboBox question is even more confusing for me.
I have no idea what you are trying to do.
-Frinny
Basically what im trying to do, is to get values from a database to put em as Buttons Texts for example:
this.button1.text=this.cbb.selectedvalue.tostring( );
the number of buttons will depend of the number of data contained in the table(which only contains an atribbute) from the database.
for example:
Table Providers:
ProviderName
Palmolive
Hersheys
Coke
In the example below i will have only 3 buttons.
I'm not sure why you would want to store this into a String Array at all then.
You need to loop through each row.
For each row you need to create a button.
For each column in the row you need to grab the properties for the button.
Then you need to add the button to a control....and loop to the next row.
-Frinny
Thanks for your reply, as you may already noted im newbie at this, so if you could show me an example of what you said in the last post, that would be superb.
I figured it out to save the values from the combobox to an array: - contador = this.cbbAux.Items.Count;
-
string[] matrix = new string[contador];
-
for (this.cbbAux.SelectedIndex = 0; this.cbbAux.SelectedIndex < contador; this.cbbAux.SelectedIndex++)
-
{
-
matrix[this.cbbAux.SelectedIndex] = this.cbbAux.SelectedValue.ToString();
-
}
The only problem is that index start in 0 and Count is a real number, so it shows me an "argument out of range exception".
I dont know how to solve this new exception.
Oh I think I know what your problem is now.
How are you retrieving your DataTable?
-Frinny
i solved it: -
for (int i = 0; i < contador; i++)
-
{
-
matrix[i] = this.cbbAux.SelectedValue.ToString();
-
if(this.cbbAux.SelectedIndex<contador-1)
-
this.cbbAux.SelectedIndex++;
-
-
}
-
-
Categorias Cate = new Categorias();
-
this.cbbAux.DataSource = Cate.ListadoGeneral();
-
this.cbbAux.ValueMember = "NombreCategoria";
-
this.cbbAux.DisplayMember = "NombreCategoria";
-
Method ListadoGeneral from Categorias Class: -
public DataTable ListadoGeneral()
-
{
-
// indicar la instancia SQL
-
this.cadenasql = string.Format
-
("Select NombreCategoria From Categorias");
-
// definir un objeto adapter
-
OleDbDataAdapter Adaptador = new OleDbDataAdapter(this.cadenasql, this.cnpuntoventa);
-
// recuperar la tabla y guardar en el dataset
-
Adaptador.Fill(this.dspuntoventa, "Categorias");
-
// retornar latabla de categorias
-
return this.dspuntoventa.Tables[0];
-
}
Ok now i know all that but i have now another question:
If Sql Query doesnt find desired values what is saved into the Dataset?
For example: -
public DataTable ListadoGeneral()
-
{
-
// indicar la instancia SQL
-
this.cadenasql = string.Format
-
("Select ClaveArticulo,NombreArticulo From Mercancia Where NombreProveedor='{0}'",
-
this.nombreproveedor);
-
// definir un objeto adapter
-
OleDbDataAdapter Adaptador = new OleDbDataAdapter(this.cadenasql, this.cnpuntoventa);
-
// recuperar la tabla y guardar en el dataset
-
Adaptador.Fill(this.dspuntoventa, "Mercancia");
-
// retornar latabla de estados
-
return this.dspuntoventa.Tables[0];
-
}
-
if query does not find elements with the specified condition, what is the query returning? and what is the Adapter filling into the dataset?, in case is really filling it.
Maybe this is really a SQL question but any help would be really apreciated.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mohamed Osman |
last post by:
If a bind a data table to a comboxbox as appose to merging the table into a
dataset the selectedvalue property does not work consistently
On loading of a form:
A datatable is created from a...
|
by: Gene Hubert |
last post by:
I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:...
|
by: Daylor |
last post by:
hi.
i have 2 combobox on form.
after i load the form.
when i select the first combobox , i want to filter the datatable that
attached to the second combobox.
i wrote :
|
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:...
|
by: XenReborn |
last post by:
Ok this should be simple.
I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database,...
|
by: gggram2000 |
last post by:
OK here's my code:
SqlConnection dbConnection = new SqlConnection(xmldb);
SqlCommand cmd = new SqlCommand(" SELECT * FROM dbo.fnInvoiceID() ", dbConnection);
cmd.CommandType =...
|
by: Ronald S. Cook |
last post by:
Using LINQ, I can bind my IEnumerable to my ComboBox no problem.
However, in the past it would be a DataTable that I could insert a new row
(e.g. "(Please select...)") and then sort it with a...
|
by: Aleksey Timonin |
last post by:
Hi guys,
I have a comboBox binded to DataTable:
comboBox.DataSource = MyDataTable;
comboBox.ValueMember = "id";
comboBox.DisplayMember = "id";
|
by: anatanat |
last post by:
hello :)
I want to bind a combobox to a specific column in a DataTable.
I want the combobox items to display distinct values.
I tried:
combo.datasource = dataTable;
combo.DisplayMember =...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
| |