Sunday, 15 September 2013

Asp.net C# Mvc3 Add database as entered value -



Asp.net C# Mvc3 Add database as entered value -

in project have 4 variables in database. filenumber, number, lastfilenumber , company.

i want create in database number of number value. if filenumber 5 , number 3, lastfilenumber 5 + 3 - 1 = 7, , should save database like

filenumber 5 number 3 lastfilenumber 7

filenumber 6 number 3 lastfilenumber 7

filenumber 7 number 3 lastfilenumber 7

my code currently:

[httppost] public actionresult create(eur1 eur1) { int filenum = convert.toint32(eur1.filenumber); int lastfilenum = convert.toint32(eur1.lastfilenumber); int num = convert.toint32(eur1.number); if (modelstate.isvalid) { for(int i=0;i<=num;i++) { db.eur1.addobject(eur1); db.savechanges(); lastfilenum = lastfilenum + 1; } homecoming redirecttoaction("create"); } homecoming redirecttoaction("create"); }

but of course of study it's saying

an object same key exists in objectstatemanager. existing object in unchanged state. object can added objectstatemanager 1 time again if in added state.

how can prepare this?

have @ for loop - add together same eur1 object 1 time again , again. on other hand, assignment of lastfilenum = lastfilenum + 1; has no meaning, because don't lastfilenum'.

recheck logic.

c# asp.net-mvc-3

No comments:

Post a Comment