为什么不EMPLOYEE_ID被插入到数据库 [英] Why is employee_id not being inserted into database

查看:103
本文介绍了为什么不EMPLOYEE_ID被插入到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <asp:TabPanel ID="AbsentTabPanel" runat="server" HeaderText="Excused Absences">
        <ContentTemplate>
        <asp:ListView ID="AbsentListView" runat="server" InsertItemPosition="LastItem"
                DataSourceID="AbsentSqlDataSource" DataKeyNames="">

            <InsertItemTemplate>
                <tr>
                    <td>
                        <asp:DropDownList ID="ExcusedAbsences_employee_idDropDownList2" runat="server">
                            <asp:ListItem Text="John Smith" Value="1" />
                            <asp:ListItem Text="Indiana Jones" Value="2" />
                        </asp:DropDownList> 

                    </td>
                    <td>
                        <!-- start date -->
                        <asp:TextBox ID="start_dt_codeTextBox" runat="server" Columns="6" Text='<%#Bind("start_dt")%>' />
                    </td>
                    <td>
                        <!-- end date -->
                        <asp:TextBox ID="end_dt_codeTextBox" runat="server" Columns="6" Text='<%#Bind("end_dt")%>' />
                    </td>
                    <td>
                        <asp:Button runat="server" CommandName="Insert" Text="insert" />
                        <asp:Button runat="server" CommandName="Clear" Text="clear" />
                    </td>
                </tr>                    
            </InsertItemTemplate>

...

<asp:SqlDataSource ID="AbsentSqlDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:Rotations3ConnectionString %>"
    SelectCommand="SELECT employee_id, start_dt, end_dt
                     FROM Excused_Absences
                    WHERE fy = @fy AND pgy = @pgy"

    UpdateCommand="UPDATE Excused_Absences
                      SET start_dt = @start_dt, end_dt = @end_dt, employee_id = @employee_id
                    WHERE absence_nbr = @absence_nbr"

    InsertCommand="INSERT INTO Excused_Absences (fy, pgy, employee_id, start_dt, end_dt)
                        VALUES (@fy, @pgy, @employee_id, @start_dt, @end_dt)"

    OldValuesParameterFormatString="old_{0}">

    <SelectParameters>
        <asp:ControlParameter Name="fy" Type="Int32" ControlID="fyTextBox" PropertyName="Text" />
        <asp:ControlParameter Name="pgy" Type="Int32" ControlID="pgyTextBox" PropertyName="Text" />
    </SelectParameters>

    <InsertParameters>
        <asp:ControlParameter Name="fy" Type="Int32" ControlID="fyTextBox" PropertyName="Text" />
        <asp:ControlParameter Name="pgy" Type="Int32" ControlID="pgyTextBox" PropertyName="Text" />
        <asp:Parameter Name="employee_id" Type="String" />
        <asp:Parameter Name="start_dt" Type="DateTime" />
        <asp:Parameter Name="end_dt" Type="DateTime" />
    </InsertParameters>

由于某些原因,当我插入约翰·史密斯和印第安纳·琼斯,在EMPLOYEE_ID没有插入到数据库中,我得到一个NULL值。我缺少什么?

For some reason when I insert John Smith or Indiana Jones, the employee_id is not inserted into the database, I get a NULL value. What am I missing?

推荐答案

找到了!很长一段时间的程序员,但新手asp.net所以我不知道是什么原因,只是周围的其他code,它没有我想同样的事情戳,我能写这样的功能:

Found it! long time programmer, but novice to asp.net so I'm not sure of the reason, but just poking around other code that did the same thing i wanted, I was able to write this function:

Protected Sub AbsentListView_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles AbsentListView.ItemInserting
    e.Values("employee_id") = DirectCast(AbsentListView.InsertItem.FindControl("ExcusedAbsences_employee_idDropDownList2"), DropDownList).SelectedValue
End Sub

我找不到这个函数的任何调用,但apparnetly它就会用我的AbsentlistView项目的每一次插入自动调用。

I couldn't find any call to this function, but apparnetly it gets called automatically with every insert of my "AbsentlistView" item.

此功能以某种方式告诉SQL命令是什么值应为下拉,因此,当SQL命令的推移,它在EMPLOYEE_ID字段中的正确值。

This function somehow tells the SQL command what the value should be for the drop down, and therefore when the SQL command goes, it has the correct value in the employee_id field.

感谢所有您的帮助。

这篇关于为什么不EMPLOYEE_ID被插入到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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