I want to register a client and one of their attributes is sex
Database: sex attribute is nvarchar
ASP.NET: I'm working with a listview to insert client data
<asp:SqlDataSource ID="clientes" runat="server"
ConnectionString="<%$ ConnectionStrings:Loja %>"
ProviderName="<%$ ConnectionStrings:Loja.ProviderName %>"
EnableCaching="true"
SelectCommand="SELECT [Id], [sexo] FROM Cliente ORDER BY Id"
InsertCommand="INSERT INTO [Cliente] ([sexo]) VALUES (@sexo)"
UpdateCommand="UPDATE [Cliente] SET [sexo] = @sexo WHERE [Id] = @Id"
DeleteCommand="DELETE FROM [Doente] WHERE [Id] = @Id">
<InsertParameters>
<asp:Parameter Name="sexo" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="sexo" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:ListView ID="listaClientes" runat="server" DataKeyNames="Id"
DataSourceID="clientes">
<ItemTemplate>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
Sexo:
<asp:RadioButtonList ID="rblSexo" runat="server"
RepeatDirection="Horizontal"
OnSelectedIndexChanged="rblSexo_SelectedIndexChanged">
<asp:ListItem Text ="Masculino" Value="1" />
<asp:ListItem Text ="Feminino" Value="2" />
</asp:RadioButtonList><br />
</InsertItemTemplate>
</asp:ListView>
My question is how will I store in the attribute (sex of DB) what the user selects in the RadioButtonList?
I thought about using:
string = "INSERT INTO [Doente] (sexo) VALUES (@sexo)";
command.Parameters.Add("@sexo", rblSexo.SelectedItem.Value);
In the Inserted Event of sqlDataSource, what do you think?