Adnan
asked on
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?
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();
}
crystalreport.png
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
http://shabdar.org/store-save-images-in-sql-server.html
ASKER
oki, but why should i convert it to binary and save it?
because image datatype in sql server will save binary data inside
did you tried the link i suggested?
did you tried the link i suggested?
ASKER
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();
ASKER
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);
did you fill the CrystalRepByteArr correctly?
does it has any value after filling?
could you paste the code which you fill this variable?
does it has any value after filling?
could you paste the code which you fill this variable?
ASKER
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);
ASKER
filedata is the CrystalRepByteArr
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?
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?
ASKER
oki i will trie to put it in a stored procedure...., the data type of Uploadfile field is varbinary(max)
change the datatype of Uploadfile to IMAGE , and try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the scenario for all files is same, you should convert it to binary and save it.