Hey everyone,
What i'm doing is building a step through form that will basically store relational keys between databases. I begin by storing Information about the individual asking about the program, I then want to query the table this was stored in to get the Unique ID that is being associated with that entry, and use that ID in an InsertCommand statement for the next table information is being inserted to. Here is my code;

Here are the two Query calls;

Here are the corresponding SqlDataSource events;

<asp:SqlDataSource ID="InsertPatInfo" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
    providername="<%$ ConnectionStrings:DataConnectionString.ProviderName %>"
        InsertCommand = "Insert into tblPatInfo(PatName, PatAge, PatState, PatCountry, PatPhone, PatCell) VALUES 
        (@PatName, @PatAge, @PatState, @PatCountry, @PatPhone, @PatCell)">
            <asp:ControlParameter ControlID = "PatInfoName" Name="PatName" PropertyName="text"/>
            <asp:ControlParameter ControlID = "PatInfoAge" Name="PatAge" PropertyName="text" />
            <asp:ControlParameter ControlID = "PatInfoState" Name="PatState" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "PatInfoCountry" Name="PatCountry" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "PatInfoPhone" Name="PatPhone" PropertyName = "text" />
            <asp:ControlParameter ControlID = "PatInfoCell" Name="PatCell" PropertyName="Text" />     


<asp:SqlDataSource ID="InsInqInfo" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
        providerName="<%$ ConnectionStrings:DataConnectionString.ProviderName %>"
        SelectCommand = "SELECT TOP 1 PatId from tblPatInfo OrderBy PatID desc"
        InsertCommand = "Insert into tblInquirer(InqPatID, InqName, InqState, InqCountry, InqPhone, InqRelation, InqVia, InqCareLevel, InqProgram) VALUES 
        (@PatID, @InqName, @InqState, @InqCountry, @InqPhone, @InqRelation, @InqVia, @InqCareLevel, @InqProgram)">
            <asp:QueryStringParameter Name="PatID" QueryStringField="PatId" Type="String" />
            <asp:ControlParameter ControlID = "InqName" Name="InqName" PropertyName="text"/>
            <asp:ControlParameter ControlID = "InqStateList" Name="InqState" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "InqCountry" Name="InqCountry" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "InqPhone" Name="InqPhone" PropertyName="Text" />
            <asp:ControlParameter ControlID = "radInqRel" Name="InqRelation" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "InitInqVia" Name="InqVia" PropertyName = "selectedvalue" />
            <asp:ControlParameter ControlID = "CareLevel" Name="InqCareLevel" PropertyName="selectedvalue" />
            <asp:ControlParameter ControlID = "ProgSelect" Name="InqProgram" PropertyName="selectedvalue" />     

I'm basically just receiving the error that there is no value stored in the PatID variable for the second insert statement. Other than that all of the data is being stored properly, just don't think the query is working correctly to get the tblPatInfo.PatID descending.
Any help would be great.
Thank you,

5 Years
Discussion Span
Last Post by nickg21

I don't think that i'm getting the PatID value either, that is what my question is, what about my code is wrong that I wouldn't be returning the value? Even if it didn't return the most recent row I have other data that should be returning a value......?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.