Linq To Sql hell

Program not submitting to the database

Page 1 of 1

7 Replies - 7891 Views - Last Post: 27 May 2010 - 02:16 PM Rate Topic: -----

#1 daarkfall  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Linq To Sql hell

Posted 26 May 2010 - 04:03 AM

As part of my current project i am attempting to use linq to SQL as part in conjunction with and MDF SQl 08 database. Upon entering the appropriate data in my form the data is being stored into a cache and is not submitting to the database



 //insert data
        private void button1_Click(object sender, EventArgs e)
        {
            
            
            DataClasses1DataContext dv = new DataClasses1DataContext { };
            DVD d = new DVD { };
            
           

            d.Title = txtTitle.Text;
            d.ID = txtId.Text;
            d.Certificate = Convert.ToInt32( txtCert.Text);
            d.Price = Convert.ToDecimal(txtPrice.Text);

            dv.DVDs.Insertonsubmit(d);
            dv.DVDs.Context.SubmitChanges();
            
        }



after reading around i have found that there have been some cases of the data submitting to a cache somewhere (i really dont know where the hell its being stored) rather than to the database.

i have also tried changing the submit commands from

 
dv.DVDs.Context.SubmitChanges();



to
dv.SubmitChanges();


to no avail i'm completely stumped

forgot to mention this is on a windows form application, i have tried the same thing on an ASP.net website and it works beautifully

in my view all the data is pulled out and is viewable (even after the program has been reset) the data is still there however when i view the table data the record has not been created or submitted .

Is This A Good Question/Topic? 0
  • +

Replies To: Linq To Sql hell

#2 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: Linq To Sql hell

Posted 26 May 2010 - 09:26 AM

If it's not getting saved in the database, that means there is some sort of conflict.
So try to submit changes inside a try catch block to check if that's the problem.

try 
{
	dgv.SubmitChanges();
}
catch (System.Reflection.ChangeConflictException ex)
{
	Debug.WriteLine(ex.Message);
}


Refer this page
Was This Post Helpful? 0
  • +
  • -

#3 daarkfall  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Re: Linq To Sql hell

Posted 26 May 2010 - 10:55 AM

@JITHU thankyou for your prompt response i gave what you where suggesting a shot and looked through the webpage

heres what i have now

            try
            {
                dv.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                      MessageBox.Show(ex.ToString());
            }



I ran a breakpoint through the submit and it didn't actually throw any errors. Also when i added a watch onto the submit again no errors seemed to appear, whilst the data still isnt being entered.

In my mind it's showing that its submitting the data whilst in actual fact its not submitting the data at all :/
Was This Post Helpful? 0
  • +
  • -

#4 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: Linq To Sql hell

Posted 26 May 2010 - 12:09 PM

OK.
I think, maybe you're overwriting the modified db each time you run your program from VS.

To check this, go to Solution Explorer, select the db, open the properties window and make sure that the "Copy to output directory" prop is set to "Copy if newer".
Was This Post Helpful? 0
  • +
  • -

#5 daarkfall  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Re: Linq To Sql hell

Posted 26 May 2010 - 12:48 PM

Hey again, yes that property was set to overright each time, it still hasn't fixed the insertion problem. I ran a watch on one of my variables which i am converting to an int32 and noticed the variable is set to 0x0000000f rather than an integer value could this cause be causing this?
Was This Post Helpful? 0
  • +
  • -

#6 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: Linq To Sql hell

Posted 27 May 2010 - 10:44 AM

View Postdaarkfall, on 26 May 2010 - 07:48 PM, said:

Hey again, yes that property was set to overright each time, it still hasn't fixed the insertion problem. I ran a watch on one of my variables which i am converting to an int32 and noticed the variable is set to 0x0000000f rather than an integer value could this cause be causing this?


No, i don't think that could be a problem.
As said here, your table must have a primary key, if you don't have one, that could be the problem.
Was This Post Helpful? 1
  • +
  • -

#7 daarkfall  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Re: Linq To Sql hell

Posted 27 May 2010 - 02:04 PM

View PostJITHU, on 27 May 2010 - 09:44 AM, said:

View Postdaarkfall, on 26 May 2010 - 07:48 PM, said:

Hey again, yes that property was set to overright each time, it still hasn't fixed the insertion problem. I ran a watch on one of my variables which i am converting to an int32 and noticed the variable is set to 0x0000000f rather than an integer value could this cause be causing this?


No, i don't think that could be a problem.
As said here, your table must have a primary key, if you don't have one, that could be the problem.


Your both a gentlemen and a scholar, thankyou for your hard work. This was the exact problem the primary key wasnt set when i set up linq. i wish i could give you more than 1 kudos :)
Was This Post Helpful? 0
  • +
  • -

#8 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: Linq To Sql hell

Posted 27 May 2010 - 02:16 PM

great to hear that the problem is solved. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1