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
No comments:
Post a Comment