4
I want to register a client and one of his attributes is sex
Database: the sex attribute is a nvarchar
ASP.NET: I am working with a listview to enter 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 doubt is how I will save in the attribute (BD sex) what the user selects in Radiobuttonlist?
I thought I’d use:
string = "INSERT INTO [Doente] (sexo) VALUES (@sexo)";
command.Parameters.Add("@sexo", rblSexo.SelectedItem.Value);
in sqlDataSource Inserted Event, what do you think?
This way it works?
– PauloHDSousa
I see some strange points in your implementation. 1 - Why do you use Nvarchar? Do you need to store data in Unicode? Sex is what? Number? or the initial? M/F? I understand that this is not directly relevant with your question but if you are using only M/F could use a char.
– jpgrassi
Solved? If positive, accept the answers because your question is still open :-(
– Renan