4 Replies - 1074 Views - Last Post: 20 April 2010 - 12:53 PM Rate Topic: -----

#1 Eagles05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 01-November 09

Select Statements in Visual Studio

Posted 19 April 2010 - 06:20 PM

Okay. So I have three tables.

I want to take info from one table and put it in a list box.
The problem is that the info requires a JOIN between two tables.

I understand that if I want to only use one table I would do:

DataRowView row;
row = (DataRowView)whateverAdapter.List[index];
listBox.Items.Add(row["Whatever"];



But how would I incorporate SQL statements, in particular JOIN statmenets into my Code?
I didn't really provide specifics, I just want to know how to use SQL statments in Visual Studio.
Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Select Statements in Visual Studio

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

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

Re: Select Statements in Visual Studio

Posted 19 April 2010 - 11:38 PM

You should use LINQ to do this. With LINQ you can query, select, join your data from various collections like tables, arrays, etc...
Was This Post Helpful? 0
  • +
  • -

#3 ParagonDevx  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 17
  • Joined: 09-April 10

Re: Select Statements in Visual Studio

Posted 20 April 2010 - 02:49 AM

You can do this several ways, but the two most basic ways are:

On a Connected Environment:
1. Perform your query
2. loop through the DataReader resulset and add the column
you want to the listbox.

On a Disconnected Environment:
1.Fill a DataTable with your query (It doesn't matter
if it's the result of a JOIN between two tables)
2.1 Bind the DataTable to the listBox
or
2.2 Loop DataTable's rows collection and add the column
you want to your listbox

Choosing between connected or disconnected environments
depends on the nature of your problem and it's important
that you understand the distinction between them. Here's a link that can clear things up:
http://csharp.net-in...rchitecture.htm

Incorporating SQL statements that contain JOINs is no
different than any other SQL statements. You still get
a table-like structure that you can access easily; You
follow the same process whether the data you want is
pulled with or without a JOIN.

Check this link out and when you're ready, post your code
and we'll give you a hand with anything that's not clear to you:

http://www.csharp-st...t/Lesson01.aspx

This post has been edited by ParagonDevx: 20 April 2010 - 03:45 AM

Was This Post Helpful? 0
  • +
  • -

#4 Eagles05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 01-November 09

Re: Select Statements in Visual Studio

Posted 20 April 2010 - 10:14 AM

I'm having some trouble understanding you.
So I would fill my datatable with a query. Where would I write this query? How would I access it once I do write it?
Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 ParagonDevx  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 17
  • Joined: 09-April 10

Re: Select Statements in Visual Studio

Posted 20 April 2010 - 12:53 PM

View PostEagles05, on 20 April 2010 - 11:14 AM, said:

I'm having some trouble understanding you.
So I would fill my datatable with a query. Where would I write this query? How would I access it once I do write it?
Thanks.


http://csharp.net-in...rchitecture.htm

http://www.csharp-st...t/Lesson01.aspx

Did you read the tutorials in those links?

That's why I put them there, in case it wasn't clear to you. Read the tutorial and test the sample code, it will teach you how to use SQL statements in Visual Studio...isn't that what you want to learn?

Here's one more after you're done with those two:

http://www.java2s.co...lebyDataRow.htm

You need to understand the basics of data access. Put some effort and read the thing, post your code and we'll help you out...

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1