Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
        {              
            connection.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandTimeout = 0;


           // cmd.CommandText = "UPDATE CREDOnet_Documents.dbo.SubUnitDocs  SET FileName= '" + sFilename + "',File=" + fileData + ",ContentType='" + contentType + "' WHERE ID =16";

            cmd.CommandText = "UPDATE CREDOnet_Documents.dbo.SubUnitDocs  SET @FileName,@FileBlob,@ContentType WHERE @LeaseDocID";


            cmd.Parameters.Add("@FileName", SqlDbType.NVarChar, 200);
            cmd.Parameters.Add("@File", SqlDbType.Image);
            cmd.Parameters.Add("@ContentType", SqlDbType.NVarChar, 200);
            cmd.Parameters.Add("@UpdatedBy", SqlDbType.NVarChar, 100);
            cmd.Parameters.Add("@UpdatedOn", SqlDbType.DateTime, 200);
            cmd.Parameters.Add("@ID", SqlDbType.Int);


            cmd.Parameters["@FileName"].Value = sFilename;
            cmd.Parameters["@File"].Value = fileData;
            cmd.Parameters["@ContentType"].Value = contentType;
            cmd.Parameters["@UpdatedBy"].Value = "System";
            cmd.Parameters["@UpdatedOn"].Value = System.DateTime.Now;
            cmd.Parameters["@ID"].Value = "16";


            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch
        {

        }
        finally
        {
            connection.Close();
        }
Posted
Updated 6-Jan-13 23:59pm
v2
Comments
prashant patil 4987 7-Jan-13 6:02am    
what error u have in above code. expain in brief..

Try:
SQL
cmd.CommandText = "UPDATE CREDOnet_Documents.dbo.SubUnitDocs  SET FileName=@FileName, File=@FileBlob, ContentT=@ContentType WHERE ID=@LeaseDocID";


Refer:
MSDN: Configuring Parameters and Parameter Data Types (ADO.NET)[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]
MSDN: SqlCommand.Parameters Property [^]
 
Share this answer
 
v2
Comments
__TR__ 7-Jan-13 6:10am    
5ed!
Congratulations for retaining MVP. :)
Sandeep Mewara 7-Jan-13 6:12am    
Thanks TR. :)
The update statement syntax is
SQL
UPDATE [TableName]
SET [Column1] = Value1,
    [Column2] = Value2,
    .
    .
    .
    [ColumnN] = ValueN
WHERE [Condition]


So your update statement should look like
SQL
UPDATE CREDOnet_Documents.dbo.SubUnitDocs  
SET FileName= @FileName,
File=@File,
ContentType=@ContentType
WHERE ID =@ID


Take a look at the below links if you are not familiar with update statement
UPDATE (Transact-SQL)[^]
UPDATE Basics in SQL Server[^]
SQL UPDATE Statement[^]
 
Share this answer
 
Comments
Sandeep Mewara 7-Jan-13 6:13am    
Yes. A 5!
__TR__ 7-Jan-13 6:20am    
Thank you.

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