c# : Insert .rpt file into database.

Posted on 2009-04-20
Last Modified: 2012-05-06

I need to add a crystal report file to a database;
it could be Sql Server/Oracle.
I have the following code;
What am I doing wrong?

I am just trying this for the SQL server 2005 database;

string sFilePath = "C\\test.rpt";

//byte[] RptData = GetRPTData(sFullReportPath);
FileStream fs = new FileStream(sFilePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] FileData = br.ReadBytes((int)fs.Length);
SqlCommand cmd = new SqlCommand("INSERT into Tab1 (Creator,Contents ) values(?,?)",myConnection);
cmd.Parameters.AddWithValue("Creator", "Tom");            
 SqlParameter blob = new SqlParameter();
   // blob.DbType = DbType.Byte;
 blob.SqlDbType = SqlDbType.VarBinary;


 int i =  cmd.ExecuteNonQuery();

I get an error for cmd.Parameters.Add(RptData);

An unhandled exception of type 'System.InvalidCastException' occurred in System.Data.dll

Additional information: The SqlParameterCollection only accepts non-null SqlParameter type objects, not Byte[] objects.
Question by:Enid_JP
    1 Comment
    LVL 100

    Accepted Solution

    Should this
    string sFilePath = "C\\test.rpt";


    string sFilePath = "C:\\test.rpt";


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
    The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
    Viewers will learn the different options available in the Backstage view in Excel 2013.
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now