c# : Insert .rpt file into database.

Posted on 2009-04-20
Medium Priority
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 101

Accepted Solution

mlmcc earned 200 total points
ID: 24222241
Should this
string sFilePath = "C\\test.rpt";


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


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Suggested Courses

809 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