Hi there,
I Have an arraylist that holds both strings and integers and I was wondering what was the simplest way to export selected elements from it to a SQL Server 2000 table?
9 1360
Loop through it?
You are going to need to be more specific then that. We need details :-)
Hi,
Ok, so I loop through it, using IEnumerator? Then shall I create a temporary datatable where the data will be sent to, just before being imported to the sql database?
ArrayLists can be accesed with [] -
//if you have mixed content
-
for (int i=0;i<myarraylist.Count;i++)
-
{
-
// do something with myarraylist[i]
-
if (myarraylist[i].GetType()==typeof(string))
-
{
-
string myval=(string)myarraylist[i]);
-
}
-
if (myarraylist[i].GetType()==typeof(int))
-
{
-
int myval=(int)myarraylist[i]);
-
}
-
}
-
-
//if content is all of same type
-
foreach(string mystring in myarraylist)
-
{
-
// do something with mystring
-
}
-
Thanks a lot Plater!
I never thought of doing it that way.
What about the export bit? Is using a temporary datatable the most effective solution?
Thanks for the link.
In the exemple given the values are included in the code: - sqlCom.Connection = dbCon
-
sqlcom.CommandType = CommandType.Text
-
sqlCom.CommandText = "INSERT INTO CLIENT_TABLE(cID, cAddress, cPhoneNumber)" _
-
" VALUES(@cID,@cAddress,@cPhoneNumber)"
-
sqlCom.Parameters.Add("@cID", SqlDbType.Int).Value = "1234567"
-
sqlCom.Parmaeters.Add("@cAddress", SqlDbType.VarChar).Value = "123 Hypoth. Street..."
-
sqlCom.Parameters.Add("@cPhoneNumber",SqlDbType.VarChar.Value="1-800-999-99999"
What is the cleanest way to use values from an arrayList directly?
Just use the values in place of the hardcoded ones? -
sqlCom.Connection = dbCon
-
sqlcom.CommandType = CommandType.Text
-
sqlCom.CommandText = "INSERT INTO CLIENT_TABLE(cID, cAddress)" _
-
" VALUES(@cID,@cAddress)"
-
sqlCom.Parameters.Add("@cID", SqlDbType.Int).Value = myarraylist[i].ToString();
-
sqlCom.Parmaeters.Add("@cAddress", SqlDbType.VarChar).Value = myarraylist[i+1].ToString();
-
-
Thanks a lot Plater, you solved my problem from A to Z, I appreciate it.
Have a good weekend.
God Bless.
peruse the System.Data.DataSet
and System.Data.SqlClient.SqlDataAdapter classes as well.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Vipin Kedia |
last post by:
Hi
I have written a code for showing the list boxes as selected using a
Listitem and the selected property of the items.
Now I have 2 list boxes in my page. But it shows only the selected values...
|
by: D |
last post by:
I've created a report with many subreports of aggregate data. I want my
client to be able to export this data to Excel to make her charts, etc. Only
one problem: one of the fields is a "SchoolYear"...
|
by: Stephen |
last post by:
I was wondering if someone can help me with an web application design
problem. I have a aspx page which builds up an arraylist called addresses
and outputs the values in the arraylist items to a...
|
by: GTi |
last post by:
I have a listview that with selected items.
But I want to "reselect" items after a refresh.
Each items have a uniqe value in the Tag object.
After a refresh some new items may be added or removed...
|
by: Stephen Miller |
last post by:
When I dynamically populate a HtmlSelect combo box, the Value property
consistently fails to return the item selected, defaulting instead to
the first item in the list. For example:
Protected...
|
by: Empire City |
last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a
RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a
ListItem in the cell. The display part works fine. I...
|
by: Santosh |
last post by:
Dear all ,
i am writting following code.
if(Page.IsPostBack==false)
{
try
{
BindSectionDropDownlist();
|
by: ajos |
last post by:
Hello friends,
After thinking about this for sometime, i decided to post this in the java forum.
Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo...
|
by: jrnowlan |
last post by:
I have the following code that takes form data from a picklist and uses the input values to query an access database. Currently everything works, but it writes the results to the same page when...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |