Click here to Skip to main content
15,905,073 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a small question
code:
C#
public bool SaveChangesAtbildes(string jautajums, string atbilde, string pareizaAtbilde,
           int punkts, int testAtbildesID)
       {
           var saveQueryChangesAtbildes =
               from ch in db.JautājumuAtbildes
               where ch.TestaAtbildesID = testAtbildesID
               select ch;
           var saglabaDatus2 = new JautājumuAtbilde
           {
               Jautājums = jautajums,
               Atbilde = atbilde,
               PareizāAtbilde = pareizaAtbilde,
               Punkts = punkts,
               TestaAtbildesID = testAtbildesID
           };
           db.JautājumuAtbildes.InsertOnSubmit(saglabaDatus2);
           db.SubmitChanges();
           return true;
       }

how to return 'false' if no row was not changed?

thanks! :)
Posted

Hi Valza,

Try to handle it through try catch block.If any error come through database then it will catch in catch block. To insert only correct data you can use validation at code level.

This link may be help you.

http://aspalliance.com/1414_LINQ_to_SQL_Part_4__Updating_our_Database.1[^]
 
Share this answer
 
Comments
valza 7-Dec-10 6:53am    
Thank you... Good answer...
I did like this.
try
{
db.SubmitChanges();
}
catch (Exception ex)
{
return false;
}

return true;

if user write int instead of string it returns false. So I can handle exception.....


thanks! :)
You need to use System.Data.Linq.ChangeSet changes = db.GetChangeSet(); before db.SubmitChanges(); to get the number of changes.

Please refer to URL http://forums.asp.net/t/1292641.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900