1 Replies - 6692 Views - Last Post: 15 October 2012 - 05:29 AM Rate Topic: -----

#1 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

How to insert data from a database into a variable?

Posted 14 October 2012 - 06:26 PM

I am trying to figure out how to take data from a database and put it into a variable, like for example if a table held the first name of a person in one column and the last name in another, i want to be able to get that last name by using the first name, then store the last name in a variable.

I can do it one way already, but i want to put each seperate value from the different columns into different variables. Like first name goes in one variable, last name goes in another. I would hope there is some way to do it that wouldnt require me to repeat a SELECT statement multiple times.

Is This A Good Question/Topic? 0
  • +

Replies To: How to insert data from a database into a variable?

#2 rgfirefly24   User is offline

  • D.I.C Lover
  • member icon


Reputation: 449
  • View blog
  • Posts: 2,186
  • Joined: 07-April 08

Re: How to insert data from a database into a variable?

Posted 15 October 2012 - 05:29 AM

you can use a single select statement. All you need to do is put the columns you want to return in the column list:

SELECT Col1, Col2, Col3 FROM Table WHERE Col4 = @Parameter



you can then use a DateReader to loop through the records and pull out the specific column you want using this syntax:

//Lets assume your DataReader object is called dr
dr["Col1"]


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1