Showing posts with label inserts. Show all posts
Showing posts with label inserts. Show all posts

Friday, March 23, 2012

Finding "Id" with "Username" selection and then Inserting

I have a simple insert statement that takes values from textboxes and inserts them into a sql server database. I would like to add a value that is selected from a dropdown list and find its corresponding unique "Id" value and insert into the database as well.

My sql statement looks like this:

string strSQL = "INSERT INTO aspnet_Expenses (ExpenseDate,RentalCar,ect..) VALUES (@.ExpenseUserId,@.ExpenseDate,@.RentalCar,ect..)";

I would like to add this to it: SELECT @.ExpenseUserId = UserId FROM aspnet_users WHERE Username = ExpenseUserName

1) How do I assign the value from the dropdown list to save as the "ExpenseUserName"

and

2) Am I on the right path with this at all?

To do this in the least number of trips to the DB, pass all the parameters you have to a stored proc. In your proc:

(1) Use the SELECT from aspnet_users to get the userid into a variable.

(2) Do your regular insert.

|||

How do I pass the values to a stored procedure? Will I need to create a blll and data access layer? I've tried learning those but I was hoping to do something a little more straight forward. I'm pretty new to all of this.

|||OK, you can start from here:Using Stored Procedures with a Command
Try it and if you have any trouble please feel free to post it.
sql

Wednesday, March 21, 2012

Find user who made table Inserts

I would like to be able to find out what user account made changes to a
few tables on my DB. I am not exactly a SQL DBA but i am sure there are
a few places that i can look. I did not see anything in the SQL Database
logfiles. Anything that i can check."Noah" <noah@.carpathiahost.com> wrote in message
news:%23Y2r7NlEIHA.6120@.TK2MSFTNGP05.phx.gbl...
>I would like to be able to find out what user account made changes to a few
>tables on my DB. I am not exactly a SQL DBA but i am sure there are a few
>places that i can look. I did not see anything in the SQL Database
>logfiles. Anything that i can check.
Unless the designer of your system chose to record that information
elsewhere you would have to use some log mining tool such as:
http://www.lumigent.com/products/le_sql.html
--
David Portas|||Noah,
There is nothing after the fact to tell you who made changes to certain rows
of data. You can set up some methods that would catch future changes, such
as:
1. Use stored procedures for updates to data and have the stored procedure
records the user who made the change.
2. Use triggers on your tables to insert data into a audit table that
records changes,
3. Use SQL Trace and SQL Profiler to track all commands against the
database.
And so on. All of these have some overhead involved and have different
rights issues and limitations. I have listed them in what I believe to be
the lowest to highest server impact.
In SQL Server 2008 there will be a new feature to do this for you in
Enterprise Edition, according to:
http://sqlblog.com/blogs/aaron_bertrand/archive/2007/09/21/elaborations-on-my-sql-server-2008-slides.aspx
http://blog.benhall.me.uk/2007/06/sql-server-2008-change-data-capture-cdc.html
RLF
"Noah" <noah@.carpathiahost.com> wrote in message
news:%23Y2r7NlEIHA.6120@.TK2MSFTNGP05.phx.gbl...
>I would like to be able to find out what user account made changes to a few
>tables on my DB. I am not exactly a SQL DBA but i am sure there are a few
>places that i can look. I did not see anything in the SQL Database
>logfiles. Anything that i can check.|||Thanks for the advice.
On 10/19/07 9:49 AM, in article #$hWWblEIHA.6120@.TK2MSFTNGP05.phx.gbl,
"Russell Fields" <russellfields@.nomail.com> wrote:
> Noah,
> There is nothing after the fact to tell you who made changes to certain rows
> of data. You can set up some methods that would catch future changes, such
> as:
> 1. Use stored procedures for updates to data and have the stored procedure
> records the user who made the change.
> 2. Use triggers on your tables to insert data into a audit table that
> records changes,
> 3. Use SQL Trace and SQL Profiler to track all commands against the
> database.
> And so on. All of these have some overhead involved and have different
> rights issues and limitations. I have listed them in what I believe to be
> the lowest to highest server impact.
> In SQL Server 2008 there will be a new feature to do this for you in
> Enterprise Edition, according to:
> http://sqlblog.com/blogs/aaron_bertrand/archive/2007/09/21/elaborations-on-my-
> sql-server-2008-slides.aspx
> http://blog.benhall.me.uk/2007/06/sql-server-2008-change-data-capture-cdc.html
>
> RLF
> "Noah" <noah@.carpathiahost.com> wrote in message
> news:%23Y2r7NlEIHA.6120@.TK2MSFTNGP05.phx.gbl...
>> I would like to be able to find out what user account made changes to a few
>> tables on my DB. I am not exactly a SQL DBA but i am sure there are a few
>> places that i can look. I did not see anything in the SQL Database
>> logfiles. Anything that i can check.
>