Setup: loading DataReader into DataTable. Trying to change a column in a DataTable after loading.
Problem: ReadOnlyException thrown while trying to modify a column.
Conditions:
- When a function (udf or system) is applied to a column with an alias in a stored procedure, the column becomes ReadOnly.
- The error does not start if the column is simply an alias without using a function.
- The error does not start if the selection is transferred to the function table, then proc selects from this function.
- The error (obviously) does not occur when setting the column property in ReadOnly in C #.
Question: Is there a way to change the procedure so that the column with the alias with the function used is not ReadOnly? I am looking for an alternative to modify C # or create a function to accomplish what proc already does.
WITH#:
var dt = new DataTable();
using( var sqlDR = objDocsFBO.GetActiveDocsMerged(KeyID) )
{
dt.Load(sqlDR);
}
foreach( DataRow dr in dt.Rows )
{
dr["DocumentPathAlias"] = "file:///" + Server.UrlEncode(dr["DocumentPathAlias"].ToString()).Replace("+", "%20");
}
SQL:
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_ActiveDocs_RetrieveMerged]
@KeyID INT
AS
BEGIN
SELECT AD.ADMergeLogID
, AD.TemplateName
, CONVERT(NVARCHAR(10), AD.InitiatedOn, 101) [CreatedOn]
, (SELECT fn.UserName FROM dbo.ufn_User_GetFullName(AD.InitiatedBy) fn) [CreatedBy]
, AD.DocumentName
, AD.DocumentPath [DocumentPathAlias]
FROM dbo.ActiveDocsMergeLog AD
WHERE AD.DocumentPath != 'DocumentPath not found.'
AND AD.KeyID = @KeyID
END
source
share