locked
Unable to use values extracted from database as variables in file creation RRS feed

  • Question

  • User-729604004 posted

     I have written a web page which connects to a database and then display 3 values from a management reporting system using the database.

    I am accessing a database using the following code:

    <asp:SqlDataSource ID="SqlToVersion" runat="server"
    ConnectionString="<%$ ConnectionStrings:WebImportOnServer %>"
    SelectCommand="SELECT [VerNo], [PeriodName], [PeriodNo] FROM [atblVersion]"
    onselecting="SqlToVersion_Selecting"></asp:SqlDataSource>
    <asp:DetailsView ID="DetView" runat="server" DataSourceID="SqlToVersion"
    Height="50px" onpageindexchanging="DetView_PageIndexChanging2"
    Width="273px" AutoGenerateRows="False">
    <Fields>
    <asp:BoundField DataField="VerNo" HeaderText="Spreadsheet Version Number" ReadOnly="True" />
    <asp:BoundField DataField="PeriodName" HeaderText="Reporting Period" ReadOnly="True"
    SortExpression="PeriodName" />
    <asp:BoundField DataField="PeriodNo" HeaderText="Period Number" ReadOnly="True"
    SortExpression="PeriodNo" />
    </Fields>
    </asp:DetailsView>

    This works perfectly, but I need to take the values displayed in the 3 datafields (VerNo , PeriodName PeriodNo ) and use them as variables in a file that is being generated from the web page. The file is generated by using a stored procedure and these 3 variables are used in this, with entries manually entered into text boxes.

    My variables are defined in this manner:
    Dim vcPeriodNo As Integer = ????

    but it is how to replace the question marks with valid code that  takes the values from the bound fields that I am stuck with. Can anyone offer any advice, I know it should be simple but I have hit a complete block.

    Friday, May 22, 2009 3:15 AM

Answers

  • User-1164060753 posted

    You could write:

    Dim myTXT as TextBox = CType(DetView.FindControl("VerNo"),TextBox)

    Dim vcPeriodNo As Integer = Cint(myTXT.Text)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2009 5:39 AM
  • User854688209 posted

    Try this:

    Dim vcVerNo As Integer
    Dim vcPeriodName As String
    Dim vcPeriodNo As Integer

    For Each row As GridViewRow In GridView1.Rows 
        vcVerNo= DirectCast(row.Cells[1].Text, Integer)
        vcPeriodName= row.Cells[1].Text
        vcPeriodNo= DirectCast(row.Cells[1].Text,Integer)
    Next

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2009 5:43 AM

All replies

  • User-1164060753 posted

    You could write:

    Dim myTXT as TextBox = CType(DetView.FindControl("VerNo"),TextBox)

    Dim vcPeriodNo As Integer = Cint(myTXT.Text)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2009 5:39 AM
  • User854688209 posted

    Try this:

    Dim vcVerNo As Integer
    Dim vcPeriodName As String
    Dim vcPeriodNo As Integer

    For Each row As GridViewRow In GridView1.Rows 
        vcVerNo= DirectCast(row.Cells[1].Text, Integer)
        vcPeriodName= row.Cells[1].Text
        vcPeriodNo= DirectCast(row.Cells[1].Text,Integer)
    Next

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2009 5:43 AM
  • User-729604004 posted

    Thanks for the suggestions, have now resolved the problem. Had a slight problem at first as I was using the square brackets [] as displayed in the answer. I could not see what was wrong - changed them to round brackets () and all was fine.

    Thanks again!

    Marc

    Tuesday, June 2, 2009 3:55 AM