2 Replies - 6030 Views - Last Post: 01 March 2010 - 02:07 PM Rate Topic: -----

#1 btull89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-February 10

save Linq to SQL query as string

Posted 01 March 2010 - 01:38 PM

I am trying to get a value from a sql data base and view it as a string.
so, How would I do that?

Also what is the a in "from a"? I did a lot of research and couldn't find an answer.
sampleDataContext db = new sampleDataContext();
var linq = from a in db.Table1s
           where a.Name == text
           select a.Check;
MessageBox.Show(linq.ToString());


Is This A Good Question/Topic? 0
  • +

Replies To: save Linq to SQL query as string

#2 btull89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-February 10

Re: save Linq to SQL query as string

Posted 01 March 2010 - 02:05 PM

I figured out the answer.
Corrected code:
sampleDataContext db = new sampleDataContext();
var linq = (from a in db.Table1s
           where a.Name == text
           select a.Check).SingleOrDefault();
MessageBox.Show(linq);


Was This Post Helpful? 0
  • +
  • -

#3 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: save Linq to SQL query as string

Posted 01 March 2010 - 02:07 PM

The 'a' is just the name of a variable and you could name it whatever you want.

You could write:

var query = from xyz in db.Table1s
            where xyz.Name == text
            select xyz.Check;




If you would like to see what sql query is generated by your linq query and sent to your underlaying database, then use the DataContext.Log which is in your case db.Log
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1