0

I keep getting an OleDbException :"No value given for one or more required parameters" - Not very specific.

I have had no luck finding a solution to my problem online. I have tried many different things like not declaring the Parameters in the form and creating them at run time in the code behind.

Here is my ugly code:

<asp:sqldatasource  ID="datasource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
    SelectCommand="SELECT [ID], [Test Data] AS Test_Data, [More Data] AS More_Data FROM [Main]" 
    UpdateCommand="UPDATE [Main] SET [Test Data]=@TestData, [More Data]=@MoreData WHERE [ID]=@ID" 
    InsertCommand="INSERT INTO [Main] ([ID], [Test Data], [More Data]) VALUES (@InsertID, @InsertTestData, @InsertMoreData)" 
    DeleteCommand="" >
    <UpdateParameters>
        <asp:ControlParameter Name="TestData" ControlId="updateTest" PropertyName="Text" />
        <asp:ControlParameter Name="MoreData" ControlId="updateMore" PropertyName="Text" />
        <asp:ControlParameter Name="InsertTestData" ControlId="insertTest" PropertyName="Text" />
        <asp:ControlParameter Name="InsertID" ControlId="insertIDD" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="InsertMoreData" ControlId="insertMore" PropertyName="Text" />
        <asp:ControlParameter Name="ID" ControlId="DropDownList2" PropertyName="SelectedValue" />
    </UpdateParameters>
</asp:sqldatasource>

    <asp:GridView ID="GridView1" runat="server" AllowSorting="true" DataSourceID="datasource"></asp:GridView>
    <br />
    <asp:DropDownList ID="insertIDD" DataSourceID="datasource" DataTextField="ID" runat="server" Font-Bold="False"></asp:DropDownList>
    <asp:TextBox ID="insertTest"  runat="server"></asp:TextBox>
    <asp:TextBox ID="insertMore" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Insert" OnClick="Insert" />
    <br />
    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="datasource" DataTextField="ID" OnTextChanged="populateDrop" AutoPostBack="true"></asp:DropDownList>
    <asp:TextBox ID="updateTest"  runat="server"></asp:TextBox>
    <asp:TextBox ID="updateMore" runat="server"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" Text="Update" OnClick="Update" />
    <br />
    <asp:Button ID="Button3" runat="server" Text="Delete" OnClick="Delete" />**

And the C# Code Behind:

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
    DataView dv = new DataView();
    protected void Page_Load(object sender, EventArgs e)
    {
        dv = (DataView)datasource.Select(DataSourceSelectArguments.Empty);
        updateTest.Text = dv[0]["Test_Data"].ToString();
        updateMore.Text = dv[0]["More_Data"].ToString();
    }

    protected void Insert(object sender, EventArgs e) 
    {
        datasource.Insert();
    }

    protected void Update(object sender, EventArgs e) 
    {
        datasource.Update();
        updateTest.Text = "";
        updateMore.Text = "";
    }

SELECT and UPDATE work without any problem. No matter what I try I cannot get the INSERT INTO command to be happy. I am sure it is something simple that I am missing, but any help would be greatly appreciated, thanks!

2
  • 2
    Would it be cause you have no Insert parameters, you do have the Update parameters though. Commented Aug 23, 2013 at 1:48
  • Silly me I know I see what you mean... pardon my newbism Commented Aug 23, 2013 at 2:05

1 Answer 1

1

this is for Update:

    <UpdateParameters>
    <asp:ControlParameter Name="TestData" ControlId="updateTest" PropertyName="Text" />
    <asp:ControlParameter Name="MoreData" ControlId="updateMore" PropertyName="Text" />
    <asp:ControlParameter Name="ID" ControlId="DropDownList2" PropertyName="SelectedValue" />
</UpdateParameters>

and this is for Insert

<InsertParameters>
<asp:ControlParameter Name="InsertTestData" ControlId="insertTest" PropertyName="Text" />
    <asp:ControlParameter Name="InsertID" ControlId="insertIDD" PropertyName="SelectedValue" />
    <asp:ControlParameter Name="InsertMoreData" ControlId="insertMore" PropertyName="Text" />
</InsertParameters>

At the end:

<asp:sqldatasource  ID="datasource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
SelectCommand="SELECT [ID], [Test Data] AS Test_Data, [More Data] AS More_Data FROM [Main]" 
UpdateCommand="UPDATE [Main] SET [Test Data]=@TestData, [More Data]=@MoreData WHERE [ID]=@ID" 
InsertCommand="INSERT INTO [Main] ([ID], [Test Data], [More Data]) VALUES (@InsertID, @InsertTestData, @InsertMoreData)" 
DeleteCommand="" >
<UpdateParameters>
    <asp:ControlParameter Name="TestData" ControlId="updateTest" PropertyName="Text" />
    <asp:ControlParameter Name="MoreData" ControlId="updateMore" PropertyName="Text" />
    <asp:ControlParameter Name="ID" ControlId="DropDownList2" PropertyName="SelectedValue" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="InsertTestData" ControlId="insertTest" PropertyName="Text" />
    <asp:ControlParameter Name="InsertID" ControlId="insertIDD" PropertyName="SelectedValue" />
    <asp:ControlParameter Name="InsertMoreData" ControlId="insertMore" PropertyName="Text" />
</InsertParameters>
</asp:sqldatasource>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.