|
-
Sep 27th, 2005, 05:50 AM
#1
Thread Starter
Addicted Member
Retrieving Data
to retrieve data im using this code:
SqlConnection1.Open()
Dim x As SqlClient.SqlDataReader
Dim s
SqlCommand1.CommandText = "Select sum(I_AMOUNT) from INVOICES where I_YEAR = '" & ComboBox6.Text & "'"
x = SqlCommand1.ExecuteReader()
While (x.Read())
s = x.GetValue(0)
End While
x.Close()
TextBox1.Text = s
SqlConnection1.Close()
this code allows me to retrieve only one row of data
what should i do in order to retrieve many rows and display them in a datagrid
is there something to use instead of x.getvalue(0)
-
Sep 27th, 2005, 05:56 AM
#2
Lively Member
Re: Retrieving Data
I don't know if this works...
Put a breakpoint on while and see if it loops more than one time.
If it does, put a Count = Count+1 before the GetValue and then change s = x.GetValue(0), to s = x.GetValue(count)
NOT TESTED! See for yourself.
----------------------------------------------------
Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
----------------------------------------------------
-
Sep 27th, 2005, 05:59 AM
#3
Re: Retrieving Data
It probably does get more than one row of data but you're only taking a value from the very last row because you are overwriting the contents of the "s" variable each time through the loop.
-
Sep 27th, 2005, 06:12 AM
#4
Lively Member
Re: Retrieving Data
Try this...
VB Code:
SqlConnection1.Open()
Dim x As SqlClient.SqlDataReader
Dim s
SqlCommand1.CommandText = "Select sum(I_AMOUNT) from INVOICES where I_YEAR = '" & ComboBox6.Text & "'"
x = SqlCommand1.ExecuteReader()
While (x.Read())
count=count+1
s = x.GetValue(count)
textbox1.text=s ' Set Multiline=TRUE in the object properties.... or make an array
End While
x.Close()
SqlConnection1.Close()
----------------------------------------------------
Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
----------------------------------------------------
-
Sep 27th, 2005, 06:20 AM
#5
Thread Starter
Addicted Member
Re: Retrieving Data
I need to display my data in a DataGrid
-
Sep 27th, 2005, 06:23 AM
#6
Re: Retrieving Data
waelr its normal it only return one row your using the aggregate function SUM .
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Sep 27th, 2005, 06:27 AM
#7
Lively Member
Re: Retrieving Data
LOL Asgorath, didn't noticed that...
Waelr, run your SQL and see how many records you get...lol.
----------------------------------------------------
Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
----------------------------------------------------
-
Sep 27th, 2005, 06:42 AM
#8
Re: Retrieving Data
Once you modified your sql query just use a SqlDataAdapter1 to fill a dataset and assign it to your datagrid datasouce property.
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Sep 27th, 2005, 06:49 AM
#9
Thread Starter
Addicted Member
Re: Retrieving Data
LOL
i copied and pasted the code without reading
forget about the sum
the problem persists even if i select something else
i tried assignining a datasource to the datagrid after filling the dataset but i get a problem with a "+" sign on the top left of the grid which i need to press on to display the results
-
Sep 27th, 2005, 07:24 AM
#10
Re: Retrieving Data
Set the datasource of the datagrid to a particular table in the dataset, like so:
DataGrid1.DataSource = ds.Tables(0)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|