Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to pass columnname as parameter to stored procedure code behind c#....
Posted
Comments
José Amílcar Casimiro 23-Apr-13 5:24am    
Why do you need to pass a column name into a stored procedure?
Zoltán Zörgő 23-Apr-13 5:35am    
I suppose this is an ADO.NET question. Please tell us what your final goal is, since it is rarely pointing to a good practice when somebody is passing column name to a stored procedure. Although you can do this since it is a string as any other, and you can build and use dynamic query inside a stored procedure (with some limitations trough).
Sandeep Mewara 23-Apr-13 7:26am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Korathu 2 23-Apr-13 9:17am    
I want to pass column name from c# code behind and sort as per the column name....My SP as follows:
SELECT a.AssetId, a.SerialNo, a.ServiceTag, a.CostCenterId, a.AssetStatusId, a.AssetConditionId, a.Description, a.AssetEntryDate, a.RefId, a.RefModule, a.LoginId,
a.StoreStockId, a.AssetNo, a.BarCode, a.AssetPict, a.Notes, i.ItemName, m.Model, it.ItemType, c.CategoryName, b.BrandName, ac.AssetCondition, cc.CostCenter,
CASE WHEN taissue.RefId = 0 THEN 'Not Assigned' WHEN taissue.RefModule = 'D' THEN
(SELECT Department
FROM TblDepartment
WHERE DepartmentId = taissue.RefId) ELSE
(SELECT PersonName
FROM TblPerson
WHERE PersonId = taissue.RefId) END AS [user], ast.AssetStatus, s.PurchaseRate, s.POInfo, s.WarrantyDate, v.VendorName, sm.PurDate, sm.PONo
FROM TblAsset AS a INNER JOIN
TblStoreStock AS ss ON a.StoreStockId = ss.StoreStockId INNER JOIN
TblStock AS s ON s.StockId = ss.StockId INNER JOIN
TblStoreEntryMaster AS sm ON sm.PurchaseId = s.PurchaseId INNER JOIN
TblItem AS i ON s.ItemId = i.ItemId INNER JOIN
TblModel AS m ON m.ModelId = i.ModelId INNER JOIN
TblIemType AS it ON m.ItemTypeId = it.ItemTypeId INNER JOIN
TblCategory AS c ON it.CategoryId = c.CategoryId INNER JOIN
TblBrand AS b ON b.BrandId = m.BrandId INNER JOIN
TblVendor AS v ON s.VendorId = v.VendorId INNER JOIN
TblAssetCondition AS ac ON ac.AssetConditionId = a.AssetConditionId left JOIN
TblAssetStatus AS ast ON ast.AssetStatusId = a.AssetStatusId INNER JOIN
TblCostCenter AS cc ON a.CostCenterId = cc.CostCenterId

LEFT join TblAssetIssueDet tbissue on tbissue.AssetId=a.AssetId
left join TblAssetIssueMst taissue on taissue.IssueId=tbissue.IssueId
left join TblDepartment d on d.DepartmentId=taissue.RefId
where

isnull(null,c.CategoryId) = c.CategoryId and
isnull(null, b.BrandId) = b.BrandId and
isnull(null,ac.AssetConditionId) = ac.AssetConditionId and
isnull(null,d.DepartmentId) = d.DepartmentId
order by isnull(@sorder,0)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900