Click here to Skip to main content
15,922,894 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Talal Sultan9-Aug-07 21:55
Talal Sultan9-Aug-07 21:55 
The SELECT command will already return the values in a table format. You need a data reader to loop through the values. You have to create your own DataTable (in this case with one column) and insert the values as you loop the data reader. If you are using SQL Server, you can use the SqlDataReader class.

Assuming you have:

sql command: SqlCommand myCommand = new SqlCommand();
data table: DataTable myTable = new DataTable();

You would have to put something like this

SqlDataReader dr = myCommand.ExecuteReader();

while (dr.Read()) // reads as long as there are values 
{
  DataRow row = myTable.NewRow();
  row[0] = dr.GetString(0); // to get the Name column
  row[1] = ...... // if you have other columns
  myTable.Rows.Add(row);
}
dr.Close();


Good luck Smile | :)

Talal


-- If this is a post that has been helpful to you, please vote for it. Thank you!

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook

GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Giorgi Dalakishvili9-Aug-07 22:03
mentorGiorgi Dalakishvili9-Aug-07 22:03 
GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
rameshbhojan10-Aug-07 0:42
rameshbhojan10-Aug-07 0:42 
AnswerRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Talal Sultan10-Aug-07 2:10
Talal Sultan10-Aug-07 2:10 
GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
rameshbhojan19-Aug-07 22:58
rameshbhojan19-Aug-07 22:58 
GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Talal Sultan19-Aug-07 23:21
Talal Sultan19-Aug-07 23:21 
AnswerRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Giorgi Dalakishvili9-Aug-07 21:56
mentorGiorgi Dalakishvili9-Aug-07 21:56 
GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
rameshbhojan19-Aug-07 21:19
rameshbhojan19-Aug-07 21:19 
GeneralRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Giorgi Dalakishvili19-Aug-07 21:22
mentorGiorgi Dalakishvili19-Aug-07 21:22 
AnswerRe: How to store the retrieved values from a coulmn of a table in an array?? Pin
Talal Sultan9-Aug-07 21:57
Talal Sultan9-Aug-07 21:57 
Questionlistview in c# Pin
monuSaini9-Aug-07 21:34
monuSaini9-Aug-07 21:34 
AnswerRe: listview in c# Pin
mav.northwind10-Aug-07 12:31
mav.northwind10-Aug-07 12:31 
AnswerRe: What to choose asp.net!!1 Pin
Albu Marius9-Aug-07 21:33
Albu Marius9-Aug-07 21:33 
GeneralRe: What to choose asp.net!!1 Pin
monuSaini9-Aug-07 23:23
monuSaini9-Aug-07 23:23 
QuestionCapturing Complete Webpage as an Image Pin
Dinesh N Samarathunga9-Aug-07 20:29
Dinesh N Samarathunga9-Aug-07 20:29 
AnswerRe: Capturing Complete Webpage as an Image Pin
Michael Sync9-Aug-07 20:35
Michael Sync9-Aug-07 20:35 
GeneralRe: Capturing Complete Webpage as an Image Pin
Dinesh N Samarathunga9-Aug-07 22:31
Dinesh N Samarathunga9-Aug-07 22:31 
AnswerRe: Capturing Complete Webpage as an Image Pin
Jax_qqq9-Aug-07 21:18
Jax_qqq9-Aug-07 21:18 
GeneralRe: Capturing Complete Webpage as an Image Pin
Dinesh N Samarathunga9-Aug-07 22:46
Dinesh N Samarathunga9-Aug-07 22:46 
QuestionGet Raw Kerberos Token to Access Exchange 2007 by IMAP Pin
Stas9-Aug-07 19:52
Stas9-Aug-07 19:52 
Questionmove user to different tab and txt field Pin
Berdril9-Aug-07 18:33
Berdril9-Aug-07 18:33 
AnswerRe: move user to different tab and txt field Pin
Berdril9-Aug-07 19:45
Berdril9-Aug-07 19:45 
AnswerRe: move user to different tab and txt field Pin
Martin#9-Aug-07 19:49
Martin#9-Aug-07 19:49 
QuestionC# bug or any mistake Pin
Xmen Real 9-Aug-07 17:56
professional Xmen Real 9-Aug-07 17:56 
AnswerRe: C# bug or any mistake Pin
Michael Sync9-Aug-07 18:11
Michael Sync9-Aug-07 18:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.