CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014
    .Net Framework, Version 4.5

    Form Data to Access Database Using VB and FormView in Visual Studio


    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">
               <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">
                <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:Button ID="btnFacility" runat="server" Text="Submit" CommandName="Insert" OnClick="btnFacility_Click" />
    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
            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 (?,?,?,?,?,?,?,?,?)">
                 <asp:ProfileParameter Name="UserName" PropertyName="userName" Type="String" />
    Thank you in advance!!!!

    Last edited by HanneSThEGreaT; May 8th, 2014 at 03:47 PM. Reason: code tags

  2. #2
    Join Date
    Jul 2001
    Sunny South Africa

    Re: Form Data to Access Database Using VB and FormView in Visual Studio

    Welcome to the forums!

    Please make use of code tags when posting code, as explained here :


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.