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;
InsertPatInfo.Insert()
InsInqInfo.Insert()

Here are the corresponding SqlDataSource events;
InsertPatInfo:

<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)">
        <InsertParameters>
            <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" />     
        </InsertParameters>    
    </asp:SqlDataSource>

InsInqInfo:

<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)">
        <SelectParameters>
            <asp:QueryStringParameter Name="PatID" QueryStringField="PatId" Type="String" />
        </SelectParameters>
        <InsertParameters>
            <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" />     
        </InsertParameters>
    </asp:SqlDataSource>

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,
NickG

I think you are not getting PatId value from table..pleaes check

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......?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.