is there really nobody who can solve this?

Discussion in 'ASP .Net Web Controls' started by André, Jun 27, 2006.

  1. André

    André Guest

    Hi,

    I have still this unsolved problem, so i post it again.
    I hope someone replies and solves this or tells me it's impossible to do
    that this way ...
    My feeling is that it must work ...

    I have a detailsview for inserting data, and a dropdownlist which
    selectedValue must be used to fill one of the field of the detailsview.
    Table 'pc' is related to table 'lok'.

    I tried a lot of things, but still without succes. Here are the two methods
    i tried with two different errors. It works only when i introduce directly a
    value in "DefaultValue" (see below)

    Thanks for help
    André


    1) first method:
    asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    ....
    InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    OldValuesParameterFormatString="original_{0}"
    ProviderName="System.Data.OleDb"
    <InsertParameters>
    <asp:parameter Name="na" Type="String" />
    <asp:parameter Name="ty" Type="String" />
    </InsertParameters>
    .....
    Code-behind:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    lok = DropDownList1.SelectedValue
    SqlDataSource1.InsertParameters.Add("lok", lokl)
    End Sub

    This gives: No value given for one or more required parameters
    ----------------------------------------------------------------------------
    -------------------------
    2) second method
    asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    ....
    InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    OldValuesParameterFormatString="original_{0}"
    ProviderName="System.Data.OleDb"
    <InsertParameters>
    <asp:parameter Name="na" Type="String" />
    <asp:parameter Name="ty" Type="String" />
    <asp:parameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
    </InsertParameters>
    ....

    Code-behind:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    lok = DropDownList1.SelectedValue
    End Sub

    This gives: You cannot add or change a record because a related record is
    required in table 'lokl'
    which means in fact that the value of the parameter is not passed!

    It works when i give directly a value: <asp:parameter Name="lok"
    Type="String" DefaultValue="1-45" />
     
    André, Jun 27, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    2
    Views:
    364
    Miguel Dias Moura
    Jun 19, 2004
  2. G Dean Blake

    Bet nobody is smart enough to solve this!!

    G Dean Blake, Jan 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    G Dean Blake
    Jan 15, 2005
  3. André
    Replies:
    0
    Views:
    340
    André
    Jun 27, 2006
  4. Replies:
    30
    Views:
    1,030
    Arne Vajhøj
    Feb 10, 2008
  5. Lodewijk van Haringhal

    please nobody who can help me with this simple script?

    Lodewijk van Haringhal, Sep 5, 2003, in forum: Javascript
    Replies:
    3
    Views:
    125
    lallous
    Sep 6, 2003
Loading...

Share This Page