elimesika
asked on
SubmitChanges not updating the data in the database
HI Experts
I have the following table in DB:
CREATE TABLE [dbo].[vdc_options](
[option_id] [int] IDENTITY(0,1) NOT NULL,
[option_name] [nvarchar](50) COLLATE Hebrew_CI_AS NOT NULL,
[option_value] [nvarchar](50) COLLATE Hebrew_CI_AS NOT NULL)
Where option_name is defined as the primary key of this table
I have defined the following table in my c# class
[Table]
private class vdc_options
{
[Column]
public int option_id { get; private set; }
[Column]
public string option_name { get; set; }
[Column]
public string option_value { get; set; }
}
and now , I am trying to update some of the values (and I have checked that there are changes)
No Exception is thrown , and the updated values are not saved to the database.
What am i missing???
Thanks
I have the following table in DB:
CREATE TABLE [dbo].[vdc_options](
[option_id] [int] IDENTITY(0,1) NOT NULL,
[option_name] [nvarchar](50) COLLATE Hebrew_CI_AS NOT NULL,
[option_value] [nvarchar](50) COLLATE Hebrew_CI_AS NOT NULL)
Where option_name is defined as the primary key of this table
I have defined the following table in my c# class
[Table]
private class vdc_options
{
[Column]
public int option_id { get; private set; }
[Column]
public string option_name { get; set; }
[Column]
public string option_value { get; set; }
}
and now , I am trying to update some of the values (and I have checked that there are changes)
No Exception is thrown , and the updated values are not saved to the database.
What am i missing???
Thanks
private static bool SaveApplicationSettingsToDB()
{
// DataContext takes a connection string.
using (DataContext db = new DataContext(ConfigurationManager.ConnectionStrings["VdcDbConnection"].ConnectionString))
{
bool result = false;
var options = (from o in db.GetTable<vdc_options>()
select o);
foreach (var option in options)
{
option.option_value = VdcAppSettings[option.option_name].Value;
}
try
{
db.SubmitChanges();
result = true;
}
catch (ChangeConflictException ex)
{
MessageBox.Show(string.Format("Failed to save changes {0}", ex.Message));
}
return result;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not a problem, glad I was able to help. ;=)
ASKER
Works GREAT!!!