...

View Full Version : Visual Web Developer 2008 - Hot To Show Total Of Column After Running A Query?



Mehdi72
04-11-2012, 01:22 AM
I've connected my sql database to VWD 2008 and have added a select where query. One of the columns shows a fee. I want a small label under the column to show the total of those feels but I don't want to add a column in the database itself. How do I do this?

http://soccer-europe.com/Transfers/Web_Player_Search_001.png

alykins
04-11-2012, 01:36 AM
during your post-back calculate your total and store it as a variable and populate an object with it

Mehdi72
04-11-2012, 01:48 AM
I just started using VWD yesterday so I have no idea how to do that.

alykins
04-11-2012, 01:52 AM
what is VWD?
what language are you using?

scratch that i googled it- from my understanding its visual studio light- what language are you using?

Mehdi72
04-11-2012, 01:59 AM
Visual Web Developer 2008, similar to Visual Studio. It uses aspx. It's driven by toolbars and wizards.

alykins
04-11-2012, 02:34 AM
the simple answer is bind a label to it- but since you are using toolbars and wizards i have no clue what kind of interface you have available- can you access the code behind? you need to do some calculation somewhere and then fill a label

Mehdi72
04-11-2012, 02:48 AM
the simple answer is bind a label to it- but since you are using toolbars and wizards i have no clue what kind of interface you have available- can you access the code behind? you need to do some calculation somewhere and then fill a label

Hi

Yes I can view the code. I can add a label but I don't understand how to perform a caculation on the query itself. Here's the datasource if it helps?



<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TransfersConnectionString %>"
SelectCommand="SELECT [Player], [Position], [Previous Club] AS Previous_Club, [Transfer Fee] AS Transfer_Fee, [New Club] AS New_Club, [Type], [League], [Window] FROM [Summer_2001_2011] WHERE ([Player] = @Player)">
<SelectParameters>
<asp:ControlParameter ControlID="player" Name="Player" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>

alykins
04-11-2012, 02:52 AM
what is VWD?
what language are you using?

scratch that i googled it- from my understanding its visual studio light- what language are you using?


..... what.... language.... are.... you.... using?! :confused:
asp and aspx are not languages asp is typically vbscript and aspx is typically vb or C# of the three I know vb and C# extensively (sorry can't help vbs) so again- what language are you using?

Mehdi72
04-11-2012, 02:56 AM
Visual Basic. There's also an option to use Visual C#.

alykins
04-11-2012, 03:14 AM
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim cnstr As String = "demo connection string"
Dim Query As String = "select * from table"
Dim tmptbl As New DataTable

Dim conn As New SqlConnection(cnstr)
Using conn
conn.Open()
Dim cmd As New SqlCommand(Query, conn)
cmd.CommandType = CommandType.Text
Using cmd
Dim dr As SqlDataReader = cmd.ExecuteReader
tmptbl.Load(dr)
End Using
conn.Close()
End Using

Dim number As Integer = calc(tmptbl.Rows(0)(0).ToString, tmptbl.Rows(1)(1).ToString)
Label1.Text = number.ToString
End Sub

Private Function calc(ByVal s1 As String, ByVal s2 As String) As Integer
Dim i As Integer = Integer.Parse(s1)
Dim j As Integer = Integer.Parse(s2)
Dim total As Integer

'do some math function...

Return total
End Function


should be enough to get you started- you will need to figure out how to get you index- follow the link in my sig for the msdn class lib... also most searches with the key words of class C# or VB will hit the msdn lib as top hit

note- this is a windows form- quicker to make a sln as form, but concept is the same... attach that process to a page load or a button click or whatever



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum