一个SqlDataSource insert插入数据问题
mlzzk 2006-07-05 01:09:46 代码如下:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" theme="Theme1"%>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.SqlDataSource1.Insert()
Me.TextBoxcard.Text = ""
Me.TextBoxname.Text = ""
Me.TextBoxmphone.Text = ""
Me.TextBoxphone.Text = ""
Me.TextBoxsfz.Text = ""
Me.Label1.Text = "操作提示:添加成功!"
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:oldstuConnectionString %>"
selectcommand="select card,name,sex,age,sfz,sch,phone,mphone,grade,ifyes,fangshi,shouchuren,comuser from stu_info oder by id desc"
InsertCommand="INSERT INTO [stu_info] (card,name,sex,age,sfz,sch,phone,mphone,grade,ifyes,fangshi,shouchuren,comuser) VALUES (@card,@name,@sex,@age,@sfz,@sch,@phone,@mphone,@grade,@ifyes,@fangshi,@shouchuren,@comuser)">
<InsertParameters>
<asp:FormParameter Name=card FormField=TextBoxcard />
<asp:FormParameter Name=name FormField=TextBoxname />
<asp:FormParameter Name=sfz FormField=TextBoxsfz />
<asp:FormParameter Name=phone FormField=TextBoxphone />
<asp:FormParameter Name=mphone FormField=TextBoxmphone />
<asp:ControlParameter ControlID=sexDropDownList PropertyName=SelectedValue Name=sex />
<asp:ControlParameter ControlID=ageDropDownList PropertyName=SelectedValue Name=age />
<asp:ControlParameter ControlID=schDropDownList PropertyName=SelectedValue Name=sch />
<asp:ControlParameter ControlID=gradeDropDownList PropertyName=SelectedValue Name=grade />
<asp:ControlParameter ControlID=ifyesDropDownList PropertyName=SelectedValue Name=ifyes />
<asp:ControlParameter ControlID=fangshiDropDownList PropertyName=SelectedValue Name=fangshi />
<asp:ControlParameter ControlID=shouchurenDropDownList PropertyName=SelectedValue Name=shouchuren />
<asp:ControlParameter ControlID=comuserDropDownList PropertyName=SelectedValue Name=comuser />
</InsertParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Width="183px"></asp:Label><br />
卡号:<asp:TextBox ID="TextBoxcard" runat="server"></asp:TextBox><br />
姓名:<asp:TextBox ID="TextBoxname" runat="server"></asp:TextBox><br />
性别:<asp:DropDownList ID="sexDropDownList" runat="server">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:DropDownList><br />
年龄:<asp:DropDownList ID="ageDropDownList" runat="server">
<asp:ListItem>18</asp:ListItem>
<asp:ListItem Value="19">19</asp:ListItem>
<asp:ListItem Value="20">20</asp:ListItem>
<asp:ListItem Value="21">21</asp:ListItem>
<asp:ListItem Value="22">22</asp:ListItem>
<asp:ListItem Value="23">23</asp:ListItem>
<asp:ListItem Value="24">24</asp:ListItem>
<asp:ListItem Value="25">25</asp:ListItem>
<asp:ListItem Value="26">26</asp:ListItem>
<asp:ListItem Value="27">27</asp:ListItem>
</asp:DropDownList><br />
身份证:<asp:TextBox ID="TextBoxsfz" runat="server"></asp:TextBox><br />
学校:<asp:DropDownList ID="schDropDownList" runat="server">
<asp:ListItem Value="西安翻译学院"></asp:ListItem>
<asp:ListItem Value="西安外事学院"></asp:ListItem>
<asp:ListItem Value="西京大学"></asp:ListItem>
<asp:ListItem Value="西安思源学院"></asp:ListItem>
</asp:DropDownList><br />
电话:<asp:TextBox ID="TextBoxphone" runat="server"></asp:TextBox><br />
手机:<asp:TextBox ID="TextBoxmphone" runat="server"></asp:TextBox><br />
会员级别:<asp:DropDownList ID="gradeDropDownList" runat="server">
<asp:ListItem Value="1">普通会员</asp:ListItem>
<asp:ListItem Value="2">培训部实践卡</asp:ListItem>
</asp:DropDownList><br />
是否开通及时雨:<asp:DropDownList ID="ifyesDropDownList" runat="server">
<asp:ListItem Value="1">开通</asp:ListItem>
<asp:ListItem Value="0">不开通</asp:ListItem>
</asp:DropDownList><br />
售出方式:<asp:DropDownList ID="fangshiDropDownList" runat="server">
<asp:ListItem Value="兼职"></asp:ListItem>
<asp:ListItem Value="社团"></asp:ListItem>
<asp:ListItem>促销</asp:ListItem>
</asp:DropDownList><br />
售出人:<asp:DropDownList ID="shouchurenDropDownList" runat="server" DataSourceID="SqlDataSource2"
DataTextField="shouchuren" DataValueField="shouchuren">
</asp:DropDownList><br />
公司员工:<asp:DropDownList ID="comuserDropDownList" runat="server">
<asp:ListItem>李亮</asp:ListItem>
<asp:ListItem>杨军伟</asp:ListItem>
</asp:DropDownList><br />
<asp:Button ID="Button1" runat="server" Text="确定添加" OnClick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:oldstuConnectionString %>"
SelectCommand="SELECT [shouchuren] FROM [stu_shouchuren]"></asp:SqlDataSource>
</asp:Content>
为什么TextBoxcard 等textbox的值不能插入呢?