[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

How to bind an SQL Server 2005 query to DataGridView in .Net3.5?

Asked by cosie in MS SQL Server, SQL Server 2005, .NET Framework 3.x versions

Hi,

I use .Net3.5 and SqlServer 2002 and I have to show the results of an SQL query in a DataGridView.

I don't have edit access to the Database, I can only execute querries.
I don't know even the qury itself, it has been created by the Database Developer part of our Company.

If I run the query in the Query Browser, it works, and creates a result view with some columns and data...

How can I bind this query to the datagridview to build the columns automatically and fill the data in?
da.Fill(ds, "table")
I other words how to fill the data adapter with this query?
What to write to the "table" name, when I use a joined select from multiple tables?





1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
Sql="select a.tid, b.utid, username, pontszamszorzo, sum(szamla_rendbol) szamla_rendbol,
sum(sajatszamlapont) sajatszamlapont,  sum(rendpont) rendpont, sum(hitelpont) hitelpont,
sum(szamla_rendbol+sajatszamlapont+rendpont+hitelpont) ossz_pont,
(select telephelynev from teleph t where t.telephelyid=b.utid) telephely 
from
(select a.tid, a.crus, sum(case when a.rbkod is not null and br.crus is null then a.menny else 0 end) szamla_rendbol,
sum(case when (a.rbkod is null or br.crus is not null) then a.menny*isnull(a.pontszorzo,0) else 0 end) sajatszamlapont, 
0 rendpont, 0 hitelpont
from kiszmlit a join kiszmla b on a.kiszamlakod=b.kiszamlakod left join berendit br 
on br.btkod=a.rbtkod and br.berendkod=a.rbkod and br.tszam=a.rtszam join cikk c on a.cikkid=c.cikkid
where b.bizdatum between @bizdatumtol  and @bizdatumig  and a.cikkid<>3511 and a.menny>0
group by a.tid, a.crus
union all
select isnull(jk.tid, a.tid) tid, isnull(jk.crus,a.crus) crus, sum(case when a.rbkod is not null and br.crus is null then a.menny else 0 end) szamla_rendbol,
sum(case when (a.rbkod is null or br.crus is not null) then a.menny*isnull(a.pontszorzo,0) else 0 end) sajatszamlapont, 
0 rendpont, 0 hitelpont
from kiszmlit a join kiszmla b on a.kiszamlakod=b.kiszamlakod left join berendit br 
on br.btkod=a.rbtkod and br.berendkod=a.rbkod and br.tszam=a.rtszam join cikk c on a.cikkid=c.cikkid
left join kiszmlit jk on a.kbtkod=jk.kbtkod and a.kbkod=jk.kbkod and a.ktszam=jk.ktszam and jk.menny>0
where b.bizdatum between @bizdatumtol  and @bizdatumig  and a.cikkid<>3511 and a.menny<0
group by isnull(jk.tid, a.tid), isnull(jk.crus,a.crus)
union all
select a.tid, br.crus, 0 szamla_rendbol, 0 sajatszamlapont, sum(a.menny) rendpont, 0 hitelpont
from berend ber, berendit br, kiszmlit a
where br.btkod=a.rbtkod and br.berendkod=a.rbkod and br.tszam=a.rtszam and 
ber.berendkod=br.berendkod and br.cikkid<>3511
and ber.bizdatum between @bizdatumtol  and @bizdatumig 
and br.crus is not null and datediff(hh,br.crdti, a.crdti)>1
group by a.tid, br.crus
union all
select a.tid, a.crus, 0 szamla_rendbol, 0 sajatszamlapont, 0 rendpont, 
sum(20) hitelpont 
from kiszmla a
where a.bizdatum between @bizdatumtol  and @bizdatumig 
and a.fizmodid in (11,12,27,28,29,30,31)  and a.bizstatus in (1,2)
group by a.tid, a.crus
union all
select b.tid, b.crus, 0 szamla_rendbol, 0 sajatszamlapont, 0 rendpont, 
sum(-20) hitelpont 
from kiszmla a, kiszmla b
where a.bizdatum between @bizdatumtol  and @bizdatumig  and a.bizstatus=3
and a.stornobkod=b.kiszamlakod
and a.fizmodid in (11,12,27,28,29,30,31) 
group by b.tid, b.crus
) a, users b where a.crus=b.usercode
group by a.tid, username, pontszamszorzo, b.utid"
 
Dim connString As String = "Provider=SQLOLEDB;Data Source=" & server & ";Initial Catalog=" & db & ";User Id=" & userid & ";Password=" & password & ";"
 
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter(Sql, myConnection)
 
Dim ds As DataSet = New DataSet
da.Fill(ds, "table")
form.datagridview.DataSource = ds.Tables(0)
[+][-]01/19/09 07:33 AM, ID: 23411449Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 07:47 AM, ID: 23411593Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 07:55 AM, ID: 23411667Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 08:11 AM, ID: 23411840Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 08:36 AM, ID: 23412071Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 08:39 AM, ID: 23412102Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 08:53 AM, ID: 23412246Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MS SQL Server, SQL Server 2005, .NET Framework 3.x versions
Sign Up Now!
Solution Provided By: cosie
Participating Experts: 1
Solution Grade: A
 
[+][-]01/19/09 08:55 AM, ID: 23412263Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625