Wednesday, March 28, 2012

insert, update issue - stored procedure workaround

any stored procedure guru's around ?

I'm going nuts around here.
ok basically I've create a multilangual website using global en localresources for the static parts and a DB for the dynamic part.
I'm using the PROFILE option in asp.net 2.0 to store the language preference of visitors. It's working perfectly.

but Now I have some problems trying to get the right inserts.

basically I have designed my db based on this article:
http://www.codeproject.com/aspnet/LocalizedSamplePart2.asp?print=true

more specifically:
http://www.codeproject.com/aspnet/LocalizedSamplePart2/normalizedSchema.gif

ok now let's take the example of Categorie, Categorie_Local, and Culture

I basically want to create an insert that will let me insert categories into my database with the 2 language:

eg.
in categorie I have ID's 1 & 2
in culture I have:
ID: 1
culture: en-US
ID 2
culture: fr-Be

now the insert should create into Categorie_Local:

cat_id culture_id name
1 1 a category
1 2 une categorie

and so on...

I think this thing is only do-able with a stored procedure because:

1. when creating a new categorie, a new ID has to be entered into Categorie table
2. into the Categorie_local I need 2 rows inserted with the 2 values for 2 different cultures...

any idea on how to do this right ?
I'm a newbie with ms sql and stored procedures :s

help would be very very appreciated!
thanks a lotOK I got it ;)

it's not the best procedure out there I guess since I'm statically assigning my culture_id's but in this case 2 language are more than enough ;)

1 CREATEPROCEDURE [dbo].[InsCategories]2-- Add the parameters for the stored procedure here3@.cat_naam_envarchar(200),4@.cat_naam_nlvarchar(200),5@.cat_dateDateTime6AS7SET NOCOUNT ON;8BEGIN TRAN AddCategory9DECLARE @.cat_idint10Insert into Categorie11(Cat_date)12VALUES (@.cat_date)1314SELECT15@.cat_id=@.@.Identity1617--static: culture_id=1 for dutch18--static: culture_id=2 for english19Insert Into Categorie_Local20(cat_id, culture_id, catnaam)21VALUES (@.cat_id,1,@.cat_naam_nl)2223Insert Into Categorie_Local24(cat_id, culture_id, catnaam)25VALUES (@.cat_id,2,@.cat_naam_en)2627COMMIT Tran AddCategory28
sql

No comments:

Post a Comment