Quick SQL Blog

By admin on May 31st, 2012

Just a quick blog to say a few things:

Firstly, exams are over, woo! Only had 3, but there was still the cramming of revision towards the end, particularly for the Quantitative Methods and Software Engineering modules, but I think overall things went pretty well.

I have a few projects for over the summer, and I’ll post another blog about those over the next few days, but I’ve just spent the last day(ish) trying to fix a strange bug I’ve had while trying to make a Linq Database in C#.

In Linq, there is a lovely parameter which you can set for the primary key, which makes the Database create the key. i.e, if I had 200 customers, and they all needed (of course) unique bank numbers, then, instead of my program having to find the last one, andĀ iterateĀ it by one, or the user actually typing out a new number, the database will just add 1 to the number of rows already in the table, so I will have 1,2,3,4,5,6, etc. all done for me, and I don’t have to worry about clashes.

(If you’re interested, then the syntax looks something like this:)

[Column(IsPrimaryKey = true, IsDbGenerated = true)]
 public int xPrimaryKey
 {
     //accessor and mutator here
 }

However, this only works if it is declared as an integer. Yesterday, while I was typing up my columns, I forgot this, and declared it as a string, and that led to this nasty error message when I tried to create the database:

There was an error parsing the query. [ Token line number = 2,Token line offset = 15,Token in error = IDENTITY ]

Happy programming!

Leave a reply