How can i insert a CrystalReport rpt. file to database....

Hi

I have a simale form where i can browse and select the rpt. file, and i want to insert the file into my db table....!
I have added pic of my form, where i have a textfiel, a browse button, and a upload button to load rpt. file and insert it into db...can anyon guide me how i can do that?
private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(txtCrystalReport.Text);
            //crystalReportViewer1.ReportSource = cryRpt;
            //crystalReportViewer1.Refresh();

        }

Open in new window

crystalreport.png
AdnanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reza RadConsultant, TrainerCommented:
you can upload any file you want in sql server table, with field type IMAGE,
the scenario for all files is same, you should convert it to binary and save it.

0
Reza RadConsultant, TrainerCommented:
this sample is for save a picture file to sql server, but you should do similar scenario:
http://shabdar.org/store-save-images-in-sql-server.html
0
AdnanAuthor Commented:
oki, but why should i convert it to binary and save it?
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Reza RadConsultant, TrainerCommented:
because image datatype in sql server will save binary data inside
did you tried the link i suggested?
0
AdnanAuthor Commented:
yes i trued the link you suggested, and the code is working fine, sql is being executed but table column is still null and is not being updated......se the code below:
string sql = "UPDATE Setting SET Uploadfile = (convert (binary(32),@CrystalRepByteArr)) WHERE Setting_ID = 3";
                string signup = conn;
                SqlConnection myConnection = new SqlConnection(signup);
                myConnection.Open();
                SqlCommand cmd = new SqlCommand(sql, myConnection);
                
                IDbDataAdapter ad = GetDataAccess().GetNewDataAdapter(myDataAccess.GetNewCommand(sql));
               // cmd.Parameters.AddWithValue("CrystalRepByteArr", "@CrystalRepByteArr");
                IDataParameter param = GetDataAccess().AddParameter(cmd, "@CrystalRepByteArr", Adra.Data.DbType.VarBinary);
                param.Value = CrystalRepByteArr;
                
                int i = cmd.ExecuteNonQuery();

Open in new window

0
AdnanAuthor Commented:
i changed my code to , se the code below....the same is happening....the sql query is being executed if check sql server profiler....but my column is still null and its not being updated....
string sql = "UPDATE Setting SET Uploadfile = (convert (binary(32),@CrystalRepByteArr)) WHERE Setting_ID = 3";
                IDbDataAdapter ad = GetDataAccess().GetNewDataAdapter(myDataAccess.GetNewCommand(sql));
                IDbCommand idcmd = GetDataAccess().GetNewCommand(sql);
                IDataParameter param = GetDataAccess().AddParameter(idcmd, "@CrystalRepByteArr", Adra.Data.DbType.VarBinary);
                param.Value = CrystalRepByteArr;

                GetDataAccess().ExecuteSql(idcmd);

Open in new window

0
Reza RadConsultant, TrainerCommented:
did you fill the CrystalRepByteArr correctly?
does it has any value after filling?
could you paste the code which you fill this variable?


0
AdnanAuthor Commented:
yes, it has a value in bytes....se the code below...
string filePath = txtCrystalReport.Text;  

            byte[] RptData = File.ReadAllBytes(filePath);
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            byte[] FileData = br.ReadBytes((int)fs.Length);

Open in new window

0
AdnanAuthor Commented:
filedata is the CrystalRepByteArr
0
Reza RadConsultant, TrainerCommented:
ok,
and another thought is that
could you try to put this query in a stored procedure and just execute it from .net code:

UPDATE Setting SET Uploadfile =@CrystalRepByteArr WHERE Setting_ID = 3

note that declare @crystalRepByteArr as image.


and let me know what is datatype of Uploadfile field?
0
AdnanAuthor Commented:
oki i will trie to put it in a stored procedure...., the data type of Uploadfile field is varbinary(max)
0
Reza RadConsultant, TrainerCommented:
change the datatype of Uploadfile to IMAGE , and try
0
AdnanAuthor Commented:
here is a link to a article (Storing Images and BLOB files in SQL Server 2005/2008) wich iam using and it works fine for me know..... ;) juhhhuuuu.....

http://www.databasejournal.com/features/mssql/article.php/3724556/Storing-Images-and-BLOB-files-in-SQL-Server-Part-2.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.