Showing posts with label allows. Show all posts
Showing posts with label allows. Show all posts

Saturday, February 25, 2012

Can I use a stored procedure for INSERT in SqlDataSource?

Hello,

I have created a web page with a FormView that allows me to add and edit data in my database. I configured the SqlDataSource control and it populated the SELECT, INSERT, UPDATE and DELETE statements. I've created a stored procedure to do the INSERT and return to new identity value. My question is this: Can I configure the control to use this stored procedure? If so, how? Or do I have to write some code for one of the event handlers (inserting, updating?)

Any help would be appreciated.

-brian

Yes you can. Not seeing your code makes it difficult to diagnose, but it sounds like you have the SqlDataSource partially set up. Make sure you also have the insertcommand attribute set to your new stored procedure and the insertcommandtype set to "StoredProcedure". The InsertParameters should also be set to include any input parameters that are not explicitly bound within the FormView.InsertItemTemplate.

From here, you need to make sure the FormView is in insert mode, your InsertItemTemplate is properly set up, and you have an insert button with the CommandName attribute properly set to "Insert".

Once you click that button, the FormView.ItemInserting event will fire, then the SqlDataSource.Inserting event will fire.

Assuming you have all of your stored procedure input parameters properly set up within your ASPX page, your stored procedure should run, and you can pick up your return parameter from the SqlDataSource.Inserted event.

Hope this helps.

Sunday, February 19, 2012

Can I setup a Global Public View in SQL Server ?

I need a master view that gets data from different DBs located on the same SQL Server (similar with Oracle feature that allows to get data from different schemas).

Is it possible to create such a view ?

Thanks

Yes you can do it:

Create view my_view
as
select *
from
database1.schema3.table3
join database2.schema5.table6 on ....
union database3.schema5.table8


Keep in mind that if you are going to grant select privileges on this view to a specific user/role, you must grant same privileges on all underlyeing tables.

To make things simpler you can also create synonyms to that tables, like in Oracle, but you have to qualify whem with database names.

|||Thanks !

And this view can reside in any of the DBs, isn't it ?|||Yes, it can reside on any USER db, don't place it in master, tempdb, etc.