How do I insert data into my linq datacontext using a stored procedure?

Posted on 2009-04-16
Medium Priority
Last Modified: 2013-11-11
I have two asp.net 3.5 listview controls on seperate pages. When a user clicks a link from the first listview I am passing an int ID variable (TrustID) through the query string to populate the second listview. I want to be able to insert new data into this list view using a stored procedure within my datacontext. I have attached the stored procedure (code below) to my datacontext and declared it within the insert properties of the appropriate table within my datacontext. I keep getting an out of range datetime error upon insert so I'm not too sure if my insert stored procedure is written correctly? "TrustID" is the foreign key in the TrustAccounts table used to pull through data attached to another table.
ALTER PROCEDURE proc_InsertTrustAccount
	@TrustID int,
	@DueDate datetime,
	@FrequencyCode int,
	@ActionCode int,
	@Notes nvarchar(MAX)
	Insert into TrustAccounts (TrustID, DueDate, FrequencyCode, ActionCode, Notes)
	Values (@TrustID, @DueDate, @FrequencyCode, @ActionCode, @Notes)

Open in new window

Question by:Shepwedd
1 Comment

Accepted Solution

Shepwedd earned 0 total points
ID: 24159908
I've actually now managed to solve my problem as I wasn't passing the date value (along with others) through my listviews ItemInserting event (code attached) thus previously my controls weren't actually data bound resulting in null values being inserted hence the error.
protected void lvAccounts_ItemInserting(object sender, ListViewInsertEventArgs e)
        TextBox tbDueDate = (TextBox)lvAccounts.InsertItem.FindControl("DueDateInsertTextBox");
        e.Values["DueDate"] = tbDueDate.Text;
        DropDownList ddlFrequencyCode = (DropDownList)lvAccounts.InsertItem.FindControl("FrequencyInsertDDL");
        e.Values["FrequencyCode"] = ddlFrequencyCode.SelectedValue;
        DropDownList ddlActionCode = (DropDownList)lvAccounts.InsertItem.FindControl("ActionInsertDDL");
        e.Values["ActionCode"] = ddlActionCode.SelectedValue;

Open in new window


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question