Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Link to Sql - Problems on Updating Database

Reply
 
Old 07-17-2009   #1 (permalink)


VistaHome
 
 

Link to Sql - Problems on Updating Database

Hello Everyone, I'm quite new to Linq and have had some problems updating my dabase.
I don't know if it is actually happening for be using a global data context or I'm missing something.
I have my typed DataContex and one Static Public Var to initialize it located within the namespace AlpaCommon, like following:


***********************My partial datacontext*******************

// partial datacontext class
namespace
AlpaCommon
{
public partial class AlpaDataContext : System.Data.Linq.DataContext
{

//Insert method is working...
public void InsertAnimal2(Animal instance)
{
Animais.InsertOnSubmit(instance);
SubmitChanges();
}

//Delete method is working...
public void DeleteAnimal2(int animalID)
{
var animal = (from a in Animais where a.AnimalID == animalID select a).First();
Animais.DeleteOnSubmit(animal);
SubmitChanges();
}

//Update method IS NOT working...
public void UpdateAnimal2(Animal newAnimal)
{
var animal = (from a in Animais where a.AnimalID == newAnimal.AnimalID select a).First();
animal = newAnimal;
SubmitChanges();
}


*****This is where I'm instanciating the datacontext e other variables I'll need in the whole app***


//global DataContext instance
namespace AlpaCommon
{
public static class Globals
{
public static AlpaDataContext db = new AlpaDataContext();


******************* This is the call to the update method **************

....................
....................
using AlpaCommon;
namespace Animais
{
public partial class Altera : System.Web.UI.Page
{
....................
....................
....................
....................
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
//cria um novo Objeto do tipo Animal
Animal animalAltera = new Animal();
//set new values
animalAltera.AnimalID = Convert.ToInt32(Request.Params["AnimalID"]);
animalAltera.Castrado = CastradoCheckBox.Checked;
animalAltera.DisponivelAdocao = DisponivelCheckBox.Checked;
animalAltera.Adotado = AdotadoCheckBox.Checked;
animalAltera.Nome = NomeTextBox.Text;
animalAltera.Tipo = TipoDropDownList.SelectedValue;
animalAltera.Sexo = SexoDropDownList.SelectedValue;
animalAltera.Descricao = DescricaoTextBox.Text;
animalAltera.Local = LocalTextBox.Text;
animalAltera.Foto = AlteraFoto();

AlpaCommon.Globals.db.UpdateAnimal2(animalAltera);
redirect = redirectSucesso;

}
catch
{
redirect = redirectErro;
}
finally
{
Helper.Redirect(redirect);
}
}


******************************************************************************************

I'm not catching any exception, it just does not update the database.
Am I missing something in my updating or calling method?
I'm looking forward for suggestions.

Thank you

Josimari Martarelli

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Some problems after updating... Vista General
Vista updating problems Vista installation & setup
Works database 2007 and Office database 2003 .NET General
Wireless Vista problems after updating Vista General
Problems with Updating in Vista Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46