SqlDataSource InsertCommand Missing Required Parameters
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!
No comments:
Post a Comment