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

Data from datasource into array in ASP.NET

Hi there.

This is my first post although thescripts has solved many of my issues before through other people's threads.

My problem today seems simple but i can't crack it.

I'm simply trying to connect to an MSSQL database and get the data in two columns into two arrays. How hard can that be?
I've been trying to use an ObjectDataSource layer but i now think that isn't going to work so I'm moving on to having no middle layer and using a direct SQL connection but having trouble making that work too!

If anyone can offer me any helpful snippets, that'd be super.
I'm having to code in C#. My experience is mostly in php where everything seems a lot easier!!

Jon
Aug 16 '07 #1
2 1636
kenobewan
4,871 Expert 4TB
One way would be to use a datareader to loop through creating the array. HTH.
Aug 16 '07 #2
Vijey
3
Hi..
First declear the variables both array and non-array;

String[] arryCol1;
String[] arryCol2;

DataSet ds;

string strCol1,strCol2,ColValue ;
try
{
//Fist fill the dataset as per your requirement
// So, now dataset (ds) is ready; // i didn't gave the code for that...

// here we are defining the array size
arryCol1 = new String[ds.Tables[0].Rows.Count];
arryCol2 = new String[ds.Tables[0].Rows.Count];

// In this for loop we are geting all the row values
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strCol1= ds.Tables[0].Rows[i]["First_Column_Name"].ToString();
strCol2= ds.Tables[0].Rows[i]["Second_Column_Name"].ToString();
arryCol1[i] += strCol1;
arryCol2[i] += strCol2;
}
// Now the above two arrys arryCol1[], arryCol2[] contains the respective table column values.

// Inorder to verify this the below foreach loop will print the values
foreach (string Col1 in arryCol1)
{
ColValue += Col1 + ", ";
}
Response.Write(ColValue);
}
catch (Exception Ex)
{
lblMsg.Text = "Err Testing: " + Ex.Message;
}
Aug 17 '07 #3

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

Similar topics

2
by: kk | last post by:
Have 2 problems, any help is appreciated. Tab with Grids -------------- BL - fetching data from DB ( 5 secs - 10 rows) Grid Laod - 20 secs Grid Paint on tab change - 20 secs Problem: The...
0
by: mark | last post by:
My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not...
3
by: Satish | last post by:
Hi, I am facing problem with, sending data frm mdi child to mdi parent. I have search Dropdown in MDI form, depend on selection, or enter string(its like IE URL functionality) and click...
3
by: KCT | last post by:
I am creating a report screen then look like this : ItemName Quantity A 1 B 2 C 3 --End of Page-- The data is not...
4
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
3
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both...
0
by: Richard | last post by:
I have a combobox that I use to display the advertising medium that attracted a client. On the Client's table is the foreign key AdvertisingMedium, and the combobox successfully reads the data...
1
by: A. Spiehler | last post by:
I'm trying to fill a listBox control with string members from an array of objects. I think using data binding is supposed to be the easiest way to do this. I've never used data binding before and...
0
by: \Ji Zhou [MSFT]\ | last post by:
Hello Ashutosh, I see your points. As to your two new concerns, I am give the detailed comments in the following. 1. Is it possible to achieve this result without calling Update on the route...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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...
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...
0
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 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.