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

I have two 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

Who is Participating?
ShepweddAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.