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?
 
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
 
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
AdnanAuthor Commented:
oki, but why should i convert it to binary and save it?
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.