使用Visual Studio中的VB和FormView将数据表单数据访问数据库 [英] Form Data to Access Database Using VB and FormView in Visual Studio

查看:137
本文介绍了使用Visual Studio中的VB和FormView将数据表单数据访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图从Visual Studio中的FormView获取表单值,并在单击按钮时将它们提交到Access数据库。我已经尝试了很多变化,但是一直都会收到一条错误,上面写着没有参数值...



如果我使用带插入命令的VB函数,我还需要一个SQLData Source控件?请帮忙!



以下是我的FormView的代码:



 <   asp:FormView     runat   =  server    ID   =  FacilityFormView    DataSourceID   =  SqlDataSource3    OnItemCommand   =  FacilityFormView_ItemCommand   < span class =code-attribute> DataKeyNames   =  SequenceNo,来源 >  

< ItemTemplate >
...

< p < span class =code-attribute> class = head9 > 设施ID:< / p >
< div class =' 明确' > < / div >
< asp:TextBox runat = server ID = txtSeq > < / asp:TextBox >
< div class = clearB > < / div >
< p class = head9 > 提款来源:< span class =code-keyword><
/ p >
< div class =' clear' > < / div >
< asp:DropDownList ID = ddlSource runat = server DataSourceID = SqlDataSource3 DataTextField = 来源 DataValueField = < span class =code-keyword>来源 >

< ; / asp:DropDownList < span class =code-keyword>>
< div class = clearB > < / div >
< p class = head9 > 年份:< ; / p >
< div class =' clear' > < / div >
< asp:DropDownList ID = ddlYear runat = 服务器 >
< asp:ListItem = NA > 选择年份< / asp: ListItem >
< asp:ListItem = 2014 > 2014 < / asp:ListItem >
< asp:ListItem = 2015 > 2015 < / asp:ListItem >
< asp:ListItem = 2016 > 2016 < / asp:ListItem >
< asp:ListItem = 2017 > ; 2017 < / asp:ListItem >
< / asp:DropDownList
>

...

< asp:按钮 < span class =code-attribute> ID = btnFacility runat = server 文本 = 提交 CommandName = 插入 OnClick = btnFacility_Click / >
< / ItemTemplate >

< / asp:FormView >





以下是我正在使用的一些方法在我的VB文件中:

 公共 事件 ItemCommand  As  FormViewCommandEventHandler 

Sub FacilityFormView_ItemCommand( ByVal 发​​件人作为 对象 ByVal e As FormViewCommandEventArgs)
如果 e.CommandName = 插入 然后

FacilityFormView.ChangeMode(FormViewMode.Insert)


< span class =code-keyword>结束 如果

结束 Sub

受保护的 Sub btnFacility_Click(发件人作为 对象,e 正如 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 (行。 FindControl( txtMar),TextBox)

Dim cmd 作为 OleDbCommand( INSERT INTO Quarter1(SequenceNo,Source,strYear,January,Units1,February,Units2,March,Units3)VALUES(?,?,?,?, ?,?,?,?,?)

cmd.Parameters.Add( OleDbParameter( SequenceNo,se.Text))
cmd.Parameters.Add( OleDbParameter( Source,so.SelectedValue))
cmd.Parameters.Add( OleDbParameter( strYear,ye.SelectedValue))
cmd.Par ameters.Add( OleDbParameter( January,ja.Text))
cmd.Parameters.Add( OleDbParameter( Units1,un1.SelectedValue))
cmd.Parameters.Add( New OleDbParameter(< span class =code-string>
February,fe.Text))
cmd.Parameters.Add( OleDbParameter( Units2,un2.SelectedValue))
cmd.Parameters.Add( OleDbParameter( March,,ma.Text))
cmd.Parameters.Add( OleDbParameter( Uni ts3,un3.SelectedValue))

结束 Sub





这是我的数据源控件:

< pre lang =html> < asp:SqlDataSource ID = SqlDataSource3 runat = server ... SelectCommand = SELECT [ UserName],[Facility],[SequenceNo],[Source] FROM [Query1a] WHERE([UserName] =?) InsertCommand = INSERT INTO Quarter1(SequenceNo,Source,strYear, 1月,Units1,February,Units2,March,Units3)VALUES(?,?,?,?,?,?,?,?,?) >

< SelectParameters >
< asp:ProfileParameter 名称 = UserName PropertyName = userName 类型 = String / > ;
< / SelectParameters >

< / asp:SqlDataSource < span class =code-keyword>>



提前谢谢!!!!



Liz

解决方案

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

解决方案

这篇关于使用Visual Studio中的VB和FormView将数据表单数据访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆