Hi, I'm having a very similar problem and I've been over and over it and I can't figure out what's going on. I've checked all my parameters, the values are correct. I can plug the values in and execute the stored procedure in SQL Server Mgmt Studio, and it runs just fine.
The exception that's popping up is "Invalid column name 'rowguid'". "rowguid" is a valid column in the table that's being queried (and it is actually there). Here's my C# code:
string curResult = "";
string DBCONN_DF = "Data Source=" + ConfigurationManager.AppSettings["dbServer"] + ";Initial Catalog=" + ConfigurationManager.AppSettings["dbName"] + " ;Integrated Security=SSPI";
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection(DBCONN_DF);
SqlCommand cmd = new SqlCommand("dbo.mySproc", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@CustID", SqlDbType.VarChar, 10).Value = custID;
cmd.Parameters.Add("@FolderID", SqlDbType.Int).Value = curfid;
cmd.Parameters.Add("@CustFileID", SqlDbType.Int).Value = DBNull.Value;
cmd.Parameters.Add("@FileName", SqlDbType.VarChar, 255).Value = curFile;
conn.Open();
rdr = cmd.ExecuteReader();
And here is my stored procedure:
ALTER PROCEDURE [dbo].[mySproc]
-- Add the parameters for the stored procedure here
@CustID varchar(10) = null,
@FolderID int = null,
@CustFileID int = null,
@FileName varchar(255)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRY
-- Insert statements for procedure here
DECLARE @DfTable varchar(13)
SET @DfTable = dbo.GetDigitalFolderTableName(@CustID)
if @DfTable = 'CustFileTBL00' begin
SELECT
CustFileID, CustID, FolderID,
[FileName], CheckOutUser, FileSize,
DateModified, UserModified, DateDeleted,
FileOption1, FileOption2, FileOption3,
FileData, rowguid
FROM
CustFileTBL00
WHERE
((CustID = @CustID) AND (FolderID = @FolderID) AND ([FileName] = @FileName)) OR
(CustFileID = @CustFileID)
end else if @DfTable = 'CustFileTBL01' begin....... and so on
Any ideas would be greatly appreciated.
Side note (in case anyone would think to bring this up) - other apps (not written by me) use this stored procedure so I can't go changing it willy nilly.