Hi I'am practically new in C#, so I want to ask you guys some question.
Let say I have this query:
"Select EmployeeID, EmpName from PI_Employee"
How can I retrieve the result from EmployeeID column and EmpName column and put it into collections of array, so I can call the array and use it again in another function. Can I possibly do that in C# ? if so, how ? please help me guys, I'm on the edge of
nervous wreck in here so I could use a little help, any kinds of help. Thanks.
Best Regards.
--Please put "Mark as Answer" if I help you solve your problem, Thanks.
"Vanity is my favorite sins" -- John Milton/Satan ( Al Pacino )
ryan_r
Member
110 Points
134 Posts
Retrieve SQLQuery Result in Array on C#--How ????
Apr 09, 2008 08:37 AM|LINK
Hi I'am practically new in C#, so I want to ask you guys some question.
Let say I have this query:
"Select EmployeeID, EmpName from PI_Employee"
How can I retrieve the result from EmployeeID column and EmpName column and put it into collections of array, so I can call the array and use it again in another function. Can I possibly do that in C# ? if so, how ? please help me guys, I'm on the edge of nervous wreck in here so I could use a little help, any kinds of help. Thanks.
Best Regards.
"Vanity is my favorite sins" -- John Milton/Satan ( Al Pacino )
ralph.varjab...
Participant
1108 Points
207 Posts
Re: Retrieve SQLQuery Result in Array on C#--How ????
Apr 09, 2008 11:44 AM|LINK
Sounds to me that you are uncomfortable working with DataSets?
Consider using DataSets instead of Arrays, they are easier to use. And you can pass them on in functions.
I will give you a simple code here:
SqlConnection connection = new SqlConnection("connection string goes here");SqlCommand
command = new SqlCommand("select * from ......", sqlConnection); SqlDataAdapter adapter = new SqlDataAdapter(command);DataSet dataSet = new DataSet();adapter.Fill(dataSet);
// here you have your dataset filledTo access your data
dataSet.Tables[0].Rows[XXX]['YYY']
where XXX is the row index (0 to dataSet.Tables[0].Rows.Count) and YYY is the column you want to access like "EmployeeID"
Hope this helps.
My Blog
If you get the answer to your question, please mark it as the answer.
march11
Contributor
2981 Points
1350 Posts
Re: Retrieve SQLQuery Result in Array on C#--How ????
Jul 24, 2012 01:34 PM|LINK
The probelm with your solution is that you can not query datasets.
An array can be queried using Linq for example.
Datasets do have some advantages but also some short comings. I often pass them in web services requests because they are typed.