C# 将项目插入ASP.NET中的数据源

C# 将项目插入ASP.NET中的数据源,c#,asp.net,C#,Asp.net,所以我在ASP.NET中做一个小网站,我需要在数据库中插入一些数据。到目前为止,我有这个,它与我在互联网上看到的没有任何不同: <h1> Criar Novo Doente </h1> <asp:SqlDataSource ID="insertDoente" runat ="server" ConnectionString ="<%$ Connecti

所以我在ASP.NET中做一个小网站,我需要在数据库中插入一些数据。到目前为止,我有这个,它与我在互联网上看到的没有任何不同:

<h1> Criar Novo Doente </h1>

     <asp:SqlDataSource 
                ID="insertDoente"
                runat ="server"
                ConnectionString ="<%$ ConnectionStrings:principal %>"
                ProviderName = "System.Data.SqlClient"
                InsertCommand="INSERT INTO Doentes (do_Nome,do_Sexo,do_DataNascimento,do_IsInternado) VALUES (@do_Nome,@do_Sexo,@do_DataNascimento,0)" >


             <InsertParameters>
                <asp:Parameter Name="do_Nome" Type="String" />
                <asp:Parameter Name="do_Sexo" Type="String" />
                 <asp:Parameter Name="do_DataNascimento" Type="DateTime" />
            </InsertParameters>

         </asp:SqlDataSource>

     <asp:FormView ID="criarDoente" DefaultMode ="Insert" runat ="server"
                   DataSourceID="insertDoente"
                   DataKeyNames="do_Id"
                   OnItemInserted="MensagemFormView_ItemInserted">


         <InsertItemTemplate>

             <ul>
                 <li>  </li>

             </ul>

             <label>Nome: </label> <asp:TextBox ID="nome" runat ="server" MaxLength="100" TextMode="SingleLine" Text='<%# Bind("do_Nome") %>' />
             <asp:RequiredFieldValidator ID="NomeRequiredFieldValidator" ErrorMessage="Tem de indicar o nome!"
                ControlToValidate="nome" Display="Dynamic"  runat="server" />
             <br/>
             <label>Sexo </label> <asp:RadioButtonList id="Sexo" runat="server" SelectedValue='<%# Bind("do_Sexo") %>'><asp:ListItem id="Masc" Text ="Masculino" Value = "Masculino"></asp:ListItem> <asp:ListItem id="fem" Text ="Feminino" Value ="Feminino"></asp:ListItem> </asp:RadioButtonList>
             <br/>
             <label>Data de Nascimento: </label> <asp:TextBox ID="dataNasc" runat ="server" MaxLength="100" TextMode="SingleLine" Text='<%# Bind("data") %>' />
             <asp:CompareValidator id="dataCompare" ControlToValidate="dataNasc"
                Display="Dynamic" Operator="DataTypeCheck"
                Type="Date"
                ErrorMessage="A data tem de estar no formato YYYY/MM/DD"
                ForeColor="Red" runat="server" />

             <br />

             <asp:Button ID="Criar" runat="server" Text="Criar" CommandName="Insert" />






         </InsertItemTemplate>


         </asp:FormView>
当我按下按钮创建时,它会触发onItemInserted事件,但没有向数据库中添加任何内容:我是否做错了什么


编辑:insert命令的字段的顺序与在DB中的顺序相同,只是缺少ID,但这不是必需的,是吗?

您的意思是:它不插入,还是插入空行?我看不出这些字段现在是如何填充的。例如,你确定不需要FormParameter吗?他们不插入,我检查了数据库,它是空的。让我检查一下这些表单参数。我尝试了表单参数,但仍然没有结果。我解决了问题:是我的数据库没有将标识设置为主键。如果对其他人有用,请自行回答您的问题,或者将其删除。