Friday, March 9, 2012

is it easy to amend an insert statement.

I am trying to amend an SQL insert statement but it is not working.

It is as follows can anyone tell me what i am doing wrong.

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConflictDetection="CompareAllValues"

ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"DeleteCommand="DELETE FROM [useridTest] WHERE [userID] = @.original_userID AND [userName] = @.original_userName AND [listCopy] = @.original_listCopy"

InsertCommand="INSERT INTO [useridTest] ([userID], [userName], [listCopy]) VALUES (<% user.ProviderUserKey.ToString() %>, @.userName, @.listCopy)"

Please add this to your SqlDataSource:OnInserting="SQLDataSource2_OnInserting"

and

<InsertParameters>

<asp:ParameterName="userID"Type="String"/>

</InsertParameters>

Code:

protectedvoid SQLDataSource2_OnInserting(object sender,SqlDataSourceCommandEventArgs e)

{

e.Command.Parameters["@.userID"].Value =user.ProviderUserKey.ToString();

}

No comments:

Post a Comment