Hi,
I am attempting to get form values from a FormView in Visual Studio and submit them to an Access Database on a button click. I have tried SO MANY variations, but keep getting an error saying "No values for parameters..."
If I use a VB function with an insert command, do I also need an SQLData Source control? Please help!
Here is the code for my FormView:
<asp:FormView runat="server" ID="FacilityFormView" DataSourceID="SqlDataSource3" OnItemCommand="FacilityFormView_ItemCommand" DataKeyNames="SequenceNo,Source">
<ItemTemplate>
...
<p class="head9">Facility ID:</p>
<div class='clear'></div>
<asp:TextBox runat="server" ID="txtSeq"></asp:TextBox>
<div class="clearB"></div>
<p class="head9">Withdrawal Source:</p>
<div class='clear'></div>
<asp:DropDownList ID="ddlSource" runat="server" DataSourceID="SqlDataSource3" DataTextField="Source" DataValueField="Source">
</asp:DropDownList>
<div class="clearB"></div>
<p class="head9">Year:</p>
<div class='clear'></div>
<asp:DropDownList ID="ddlYear" runat="server">
<asp:ListItem Value="NA">Select a Year</asp:ListItem>
<asp:ListItem Value="2014">2014</asp:ListItem>
<asp:ListItem Value="2015">2015</asp:ListItem>
<asp:ListItem Value="2016">2016</asp:ListItem>
<asp:ListItem Value="2017">2017</asp:ListItem>
</asp:DropDownList>
...
<asp:Button ID="btnFacility" runat="server" Text="Submit" CommandName="Insert" OnClick="btnFacility_Click" />
</ItemTemplate>
</asp:FormView>
Here are some of the methods I'm using in my VB file:
Public Event ItemCommand As FormViewCommandEventHandler
Sub FacilityFormView_ItemCommand(ByVal sender As Object, ByVal e As FormViewCommandEventArgs)
If e.CommandName = "Insert" Then
FacilityFormView.ChangeMode(FormViewMode.Insert)
End If
End Sub
Protected Sub btnFacility_Click(sender As Object, e As System.EventArgs)
Dim row As FormViewRow = FacilityFormView.Row
Dim so As DropDownList = CType(row.FindControl("ddlSource"), DropDownList)
Dim ye As DropDownList = CType(row.FindControl("ddlYear"), DropDownList)
Dim un1 As DropDownList = CType(row.FindControl("ddlJan"), DropDownList)
Dim un2 As DropDownList = CType(row.FindControl("ddlFeb"), DropDownList)
Dim un3 As DropDownList = CType(row.FindControl("ddlMar"), DropDownList)
Dim se As TextBox = CType(row.FindControl("txtSeq"), TextBox)
Dim ja As TextBox = CType(row.FindControl("txtJan"), TextBox)
Dim fe As TextBox = CType(row.FindControl("txtFeb"), TextBox)
Dim ma As TextBox = CType(row.FindControl("txtMar"), TextBox)
Dim cmd As New OleDbCommand("INSERT INTO Quarter1(SequenceNo, Source, strYear, January, Units1, February, Units2, March, Units3) VALUES (?,?,?,?,?,?,?,?,?)")
cmd.Parameters.Add(New OleDbParameter("SequenceNo", se.Text))
cmd.Parameters.Add(New OleDbParameter("Source", so.SelectedValue))
cmd.Parameters.Add(New OleDbParameter("strYear", ye.SelectedValue))
cmd.Parameters.Add(New OleDbParameter("January", ja.Text))
cmd.Parameters.Add(New OleDbParameter("Units1", un1.SelectedValue))
cmd.Parameters.Add(New OleDbParameter("February", fe.Text))
cmd.Parameters.Add(New OleDbParameter("Units2", un2.SelectedValue))
cmd.Parameters.Add(New OleDbParameter("March", ma.Text))
cmd.Parameters.Add(New OleDbParameter("Units3", un3.SelectedValue))
End Sub
Here is my data source control:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ... SelectCommand="SELECT [UserName], [Facility], [SequenceNo], [Source] FROM [Query1a] WHERE ([UserName] = ?)" InsertCommand="INSERT INTO Quarter1(SequenceNo, Source, strYear, January, Units1, February, Units2, March, Units3) VALUES (?,?,?,?,?,?,?,?,?)">
<SelectParameters>
<asp:ProfileParameter Name="UserName" PropertyName="userName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Thank you in advance!!!!
Liz