Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从asp.net表单在sqlce中插入数据_Asp.net_Sql Server Ce - Fatal编程技术网

从asp.net表单在sqlce中插入数据

从asp.net表单在sqlce中插入数据,asp.net,sql-server-ce,Asp.net,Sql Server Ce,我正在尝试将名称字符串插入到测试数据库sqlce中。基本上,用户将在文本框输入框中键入名称,然后单击插入按钮。单击按钮后,将调用submit函数。我希望文本框中的文本用作insertcommand的参数。我在运行它时没有收到任何错误。但是当我检查表中的数据时,只插入null。我正在努力学习asp.net。任何帮助都将不胜感激。多谢各位 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><

我正在尝试将名称字符串插入到测试数据库sqlce中。基本上,用户将在文本框输入框中键入名称,然后单击插入按钮。单击按钮后,将调用submit函数。我希望文本框中的文本用作insertcommand的参数。我在运行它时没有收到任何错误。但是当我检查表中的数据时,只插入null。我正在努力学习asp.net。任何帮助都将不胜感激。多谢各位

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Test run</title></head>
    <script language="C#" runat = "server">
        void Submit(object o, EventArgs e) 
        {
            SqlDataSource1.Insert();            
        }       
    </script>
<body style="height: 395px">
    <form id="form1" runat="server">   
    <asp:TextBox ID="Input_box" runat="server"></asp:TextBox> 
    <asp:Button ID="Insert_button" runat="server" Text=" Insert Button"  OnClick = "Submit"/>
        <asp:SqlDataSource 
            ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            InsertCommand="INSERT INTO Incident_Table(Assignee) VALUES (@assignee)" 
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
            SelectCommand="SELECT Assignee FROM Incident_Table">
            <InsertParameters>            
                <asp:FormParameter Name="assignee"  FormField ="name"/>
            </InsertParameters>
        </asp:SqlDataSource>    
    </form>
</body>
</html>

您应该替换此:

<asp:FormParameter Name="assignee"  FormField ="name"/>
与:


[1] :谢谢你,大卫。这解决了我的问题:。我也有datetime参数,但我不确定如何将其作为参数插入。因为它不是用户输入,所以我不认为我应该使用用户FormParameter。你能提供一些想法吗?谢谢你的回答。
<asp:FormParameter Name="assignee" FormField="Input_box" />