Skip to main content

Posts

RETURNING SCOPE_IDENTITY() IN LINQ

Microsoft's Language Integrated Query is no doubt one of the most thrilling data access capability I cherish. This is just because of the flexibility you have in writing your queries within your code. The power of LINQ is not limited to the data access as in (LINQ to SQL). LINQ can be used to query the active directory, XML, SharePoint lists etc. Today I will like to discuss how to return @@IDENTITY or SCOPE_IDENTITY() in LINQ. The simple answer is to read the Id value you require immediately after submitting your changes. e.g. DataContext db = new ClassesDataContext(); PATIENT_DETAIL p = new PATIENT_DETAIL(); p.Address1 = txtAddress1.Text; p.Address2 = txtAddress2.Text; p.Address3 = txtAddress3.Text; p.Address4 = txtAddress4.Text; db.PATIENT_DETAILs.InsertOnSubmit(p); db.SubmitChanges(); int myId = p.PASNumber; // This returns the Id generated by the database (where PASNumber represents the Primary key to be returned.) QED

SharePoint 2007 Content Editor Web Part

I have recently moved into the world of development on SharePoint 2007 and I keep wondering why I haven't had time to play with this piece of software. Anyway, what I would like to discuss today is the versatility of the Content Editor Web Part which allows you to use formatted texts, tables and images as if you are working on an asp.net application. If you happen to be a developer and you have been scared of SharePoint it is time to pick up from somewhere and there are so many blogs and resources on the web to learn from. Branding a SharePoint site is obviously one of the dreary things people encounter. If you are looking to engage in branding. Just move straight to a site like http://heathersolomon.com/ I will be in touch on this soon.

VALIDATING FILE UPLOAD ASP.NET

Using the file upload in ASP.NET control is easy as ABC but there are times when you will like to validate the file type that is being uploaded and the size of the file remembering the fact that there is a maximum file size allowed in the server's config file. I will demonstrate with an image upload control (imgUpload) that stores image on a database. I am trying to ensure that only gif, png or jpg are allowed and maximum size of 300Kb. if (newFileName.EndsWith(".gif") newFileName.EndsWith(".png") newFileName.EndsWith(".jpg")) { #region Image size if (this.imgUpload.PostedFile.ContentLength { using (BinaryReader reader = new BinaryReader(imgUpload.PostedFile.InputStream)) { //Add Image byte[] img = reader.ReadBytes(imgUpload.PostedFile.ContentLength); HealthOrganisationImageFacade image = new HealthOrganisationImageFacade(); HealthOrganisationImageDTO pix = new HealthOrganisationImageDTO(0, OrganisationID, img, Organisation.Text, imgUpload.PostedFile.C...

ADD VOICE (SPEECH) CAPABILITY TO YOUR ASP.NET

Adding speech functionality to your site is so easy using the COM API available in the SAPI has a text-to-speech engine (TTS). Mind you every machine with Windows XP has SAPI and TTS. All you need do is to add a reference to a COM dll available in Microsoft Speech Object Library. The dll's name is Interop.SpeechLib.dll Namespace declare your dll as using SpeechLib; Create a text box that will contain your text, add a button that will trigger the voice conversion as shown below: protected void btnVoice_Click(object sender, EventArgs e) { SpVoice voice = new SpVoice(); try { voice.Speak(spText.Text, SpeechVoiceSpeakFlags.SVSFDefault); } catch (Exception ex) { throw ex; } } QED. You are done now. Just make sure your speakers are on and you have got the right volume.

HOW TO FIND DUPLICATE ROWS IN A TABLE (SQL)

If you are saddled with the task of finding duplicate rows in a table using SQL. It is a simple task even though it is not a place you should find yourself because you need to make sure your records are well indexed at the time of creating your table. Now that the worst has happened. All you need do is to select the row that has the duplicate values and count for each of the rows using a GROUP BY clause. For convenience sake, you can order by the same column in question as shown below: SELECT CurrentDate, COUNT(*) FROM tblSingleRate GROUP BY CurrentDate ORDER BY CurrentDate CurrentDate Count(*) 2007-03-12 1 2007-03-13 2 2007-03-14 2 2007-03-15 1 2007-03-12 1 2007-03-13 1 2007-03-14 2 2007-03-15 1 Duplicates are marked in red. QED!