First row was inserted normally, but second no. Where is the problem?
ASP.NET code for button click
try
{
Radnici r = new Radnici(); //table Radnici means Workers
r.ime_radnika = TextBox1.Text; //worker name
r.plata = Convert.ToDecimal(TextBox2.Text); //worker salary
r.valuta = DropDownList1.SelectedValue; //currency
db.Entry(r).State = System.Data.EntityState.Added; //insert data
db.SaveChanges(); //save changes
Selektuj(); //select and show data in listbox
}
catch(Exception ex)
{
Response.Write(ex.Message); //write error
}
html code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 126px">
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="130px" Width="256px" BorderStyle="Solid" BorderWidth="2px">
<asp:Label ID="Label1" runat="server" Text="Ime i prezime:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" style="margin-left: 7px"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Plata:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" style="margin-left: 57px" Width="97px"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Plata:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" style="margin-left: 57px">
<asp:ListItem>DIN</asp:ListItem>
<asp:ListItem>EUR</asp:ListItem>
<asp:ListItem>DOL</asp:ListItem>
<asp:ListItem>YEN</asp:ListItem>
<asp:ListItem>RUB</asp:ListItem>
<asp:ListItem>DEM</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Unesi" Height="18px" style="margin-left: 81px" />
</asp:Panel>
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>
</asp:ListItem>
</asp:ListBox>
</form>
</body>
</html>
mssql code
create table [dbo].[Radnici]( radnikID int primary key identity not null, ime_radnika nvarchar(50), plata decimal(18,2), valuta nvarchar(20) )
Thanks.

New Topic/Question
Reply



MultiQuote




|