Showing posts with label project. Show all posts
Showing posts with label project. Show all posts

Wednesday, March 7, 2012

copy crystalreport(.pdf) into sql database

Edited by SomeNewKid. Please post code between<code> and</code> tags.



Hi, i'm doing a project on generating a crystalreport and viewing it in a pdf format. I'm using vb.net and sql server.

i managed to general the crystalreport, save it in local directory then view it. but on the other hand i would also like to save the pdf file into my sql database. this is the difficult part and also the part which i'm stuck now. follows are all my code. hope there will be someone who can help me! thanks!

 Dim myConnection As New SqlClient.SqlConnection()
myConnection.ConnectionString = "server=(local);database=st;Trusted_Connection=yes;timeout =45"
Dim MyCommand As New SqlClient.SqlCommand()
MyCommand.Connection = myConnection
Dim CommandStr As String

CommandStr = "execute usp_rpt_note @.note_id= '" & Label_NoteID.Text & "'"
MyCommand.CommandText = CommandStr
MyCommand.CommandType = CommandType.Text
Dim MyDA As New SqlClient.SqlDataAdapter()
MyDA.SelectCommand = MyCommand
Dim myDS As New Note_DataSet()

MyDA.Fill(myDS, "usp_rpt_note")
Dim oRpt As New Note_CrystalReport1()
oRpt.SetDataSource(myDS)

oRpt.ResourceName = "Note_CrystalReport1.rpt"

Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat

Dim filename, filenamepdf, filenamexls As String
filename = UCase(Logon_Name(Request.ServerVariables("LOGON_user"))) & CStr(Year(Now())) & CStr(Month(Now())) & CStr(Day(Now())) & CStr(Hour(Now())) & CStr(Minute(Now())) & CStr(Second(Now())) & CStr(CInt(Int((100000 * Rnd(200)) + 1)))
filename = filename

filenamepdf = "D:\Inetpub\wwwroot\report\temp\" & filename & ".pdf"

DiskOpts.DiskFileName = filenamepdf

oRpt.ExportOptions.DestinationOptions = DiskOpts
oRpt.Export()

' Database operation variables
Dim connect As New SqlClient.SqlConnection("Initial Catalog=st;Data Source=localhost;Integrated Security=SSPI;Persist Security Info=True;")
Dim cmd As New SqlClient.SqlCommand("usp_copy_frm_directory", connect)
Dim p As SqlClient.SqlParameter
Dim uploaded_file As String
Dim strFileUpload As String

'uploaded_file = Request.QueryString("strFileName")
strFileUpload = "d:\Inetpub\wwwroot\report\temp\" & filename & ".pdf"
filename = strFileUpload

'File/data variables
Dim imageStream As New IO.FileStream(filename, IO.FileMode.Open)

'Dim imagestream As New IO.FileStream(Server.MapPath("ToBeUpload.doc"), IO.FileMode.Open)
Dim imageData(imageStream.Length) As Byte
Dim FileSize As Integer = CType(imageStream.Length, Integer)
Dim UploadDate As DateTime = DateTime.Now
'Dim sContentType As String = imageStream.GetType.ToString 'File1.PostedFile.ContentType
Dim sContentType As String = "Application/pdf"
'Dim sContentType As System.IO.Stream = File1.PostedFile.InputStream
' Read the image data and close the stream
imageStream.Read(imageData, 0, imageStream.Length)
imageStream.Close()

' Save the image
cmd.CommandType = CommandType.StoredProcedure

p = New SqlClient.SqlParameter("@.ImageData", SqlDbType.Image)
p.Value = imageData
cmd.Parameters.Add(p)

p = New SqlClient.SqlParameter("@.ContentType", SqlDbType.NVarChar)
p.Value = sContentType
cmd.Parameters.Add(p)

connect.Open()

cmd.ExecuteNonQuery()
connect.Close()

cmd.Dispose()
connect.Dispose()

Dim strPDF As String
strPDF = "./temp/" & filename & ".pdf"
Response.Redirect(strPDF)

Somehow it didnt work! i'm calling the above codes as a function in my pageload.

Hope help is given! thanks!!You seem to be taking the correct approach -- loading the file stream into a byte array and using that byte array as an image parameter for a stored procedure that presumably performs an insert.

Are you receiving any errors at all?

The PageLoad does not seem like the correct place for that code -- the examples I've seen/used put the code in a submit button's click event.

Terri

Sunday, February 19, 2012

Converting to MSDE - stuck already!

I just installed MSDE on my desktop and for my first project took a copy of
one of my Access 2000 databases I have used for years and upsized it. There
were many errors, especially in the queries/views. I expected some errors.
This personal database completely resides on my PC, tables and all. When I
upsized it, it copied the tables over empty - no data. So I copied and
pasted data into the Switchboard table and others.
Then I tried to open the Switchboard form that was created automatically
when I first created the database.
This was the first programming error I encountered.
Private Sub FillOptions()
' Fill in the options for this switchboard page.
' The number of buttons on the form.
Const conNumButtons = 8
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Dim intOption As Integer
' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption
' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set dbs = CurrentDb()
strSQL = "SELECT * FROM [Switchboard Items]"
strSQL = strSQL & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" &
Me![SwitchboardID]
strSQL = strSQL & " ORDER BY [ItemNumber];"
Set rst = dbs.OpenRecordset(strSQL) 'XXXXX error message occurs here
XXXXX
' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rst.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rst.EOF))
Me("Option" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
rst.MoveNext
Wend
End If
' Close the recordset and the database.
rst.Close
dbs.Close
End Sub
I get a run time error 91, object variable or With block variable not set.
Help says for error 91: First you must declare the object variable. Then you
must assign a valid reference to the object variable using the Set
statement.
I have declared and set both the database and recordset.
Since I am totally new to MSDE, can anyone guide me to where I can find out
more about this and other errors I am sure to encounter?
Thanks,
Mich
I suspect that your problem is occurring with the statement
Set dbs = CurrentDb()
How are you connecting from Access to the MSDE tables?
Chuck Heinzelman - MCSD, MCDBA
(Please respond only to the newsgroups.)
I support the Professional Association for SQL Server and its community of
SQL Server professionals.
www.sqlpass.org
"M Skabialka" <mskabialka@.NOSPAMdrc.com> wrote in message
news:uGv1gzqGFHA.3628@.TK2MSFTNGP15.phx.gbl...
> I just installed MSDE on my desktop and for my first project took a copy
of
> one of my Access 2000 databases I have used for years and upsized it.
There
> were many errors, especially in the queries/views. I expected some
errors.
> This personal database completely resides on my PC, tables and all. When
I
> upsized it, it copied the tables over empty - no data. So I copied and
> pasted data into the Switchboard table and others.
> Then I tried to open the Switchboard form that was created automatically
> when I first created the database.
> This was the first programming error I encountered.
> Private Sub FillOptions()
> ' Fill in the options for this switchboard page.
> ' The number of buttons on the form.
> Const conNumButtons = 8
> Dim dbs As Database
> Dim rst As Recordset
> Dim strSQL As String
> Dim intOption As Integer
> ' Set the focus to the first button on the form,
> ' and then hide all of the buttons on the form
> ' but the first. You can't hide the field with the focus.
> Me![Option1].SetFocus
> For intOption = 2 To conNumButtons
> Me("Option" & intOption).Visible = False
> Me("OptionLabel" & intOption).Visible = False
> Next intOption
> ' Open the table of Switchboard Items, and find
> ' the first item for this Switchboard Page.
> Set dbs = CurrentDb()
> strSQL = "SELECT * FROM [Switchboard Items]"
> strSQL = strSQL & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" &
> Me![SwitchboardID]
> strSQL = strSQL & " ORDER BY [ItemNumber];"
> Set rst = dbs.OpenRecordset(strSQL) 'XXXXX error message occurs
here
> XXXXX
> ' If there are no options for this Switchboard Page,
> ' display a message. Otherwise, fill the page with the items.
> If (rst.EOF) Then
> Me![OptionLabel1].Caption = "There are no items for this
switchboard
> page"
> Else
> While (Not (rst.EOF))
> Me("Option" & rst![ItemNumber]).Visible = True
> Me("OptionLabel" & rst![ItemNumber]).Visible = True
> Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
> rst.MoveNext
> Wend
> End If
> ' Close the recordset and the database.
> rst.Close
> dbs.Close
> End Sub
> I get a run time error 91, object variable or With block variable not set.
> Help says for error 91: First you must declare the object variable. Then
you
> must assign a valid reference to the object variable using the Set
> statement.
> I have declared and set both the database and recordset.
> Since I am totally new to MSDE, can anyone guide me to where I can find
out
> more about this and other errors I am sure to encounter?
> Thanks,
> Mich
>

Converting To ADP, Reference Recommendations

I have been creating Access applications since version 2.0 and may soon
become involved with a project that will convert an existing database
into an ADP. I would consider myself verbose in VBA, but inexperienced
using a SQL server back end. Typically when faced with a new challenge
like this one, I will read technical articles & books plus start
experimenting with code. I am sure there are many of you out there
that understand the issues I will have to confront (it worked in
'just' Access, but now...). I would appreciate recommendations
regarding books, web page links, etc., that will be helpful in my next
project.
Access version 2000 - possibly moving to 2003 next year.
Regards,
Bob<boborta@.hotmail.com> wrote in message
news:1162223068.352845.97040@.i42g2000cwa.googlegroups.com...
> I have been creating Access applications since version 2.0 and may soon
> become involved with a project that will convert an existing database
> into an ADP. I would consider myself verbose in VBA, but inexperienced
> using a SQL server back end. Typically when faced with a new challenge
> like this one, I will read technical articles & books plus start
> experimenting with code. I am sure there are many of you out there
> that understand the issues I will have to confront (it worked in
> 'just' Access, but now...). I would appreciate recommendations
> regarding books, web page links, etc., that will be helpful in my next
> project.
> Access version 2000 - possibly moving to 2003 next year.
> Regards,
Keep in mind that you can use SQL Server as a back-end and continue to use
an access mdb as the front-end. Many developers use this model. You can
still use SQL Server functionality like views, stored procedures, etc.. I
have had difficulties with ADPs and no longer attempt to use them. I also
have questions about the future of ADPs. Others have different views. Google
groups for "access adp pros cons" and you'll see there has been a lot of
discussion on this. Perhaps it has already been decided that this project
will be ADP. If so then good luck.
If the requirement is to move the data to SQL Server but the format of the
front-end is still open I would generally recommend using mdb with linked
tables to SQL Server. A lot would depend on why you are upgrading, the
application itself, the experience of the developers, etc. This is all of
course in my opinion.|||Try the book:
Microsoft Access Developers Guide to SQL Server
by Mary Chipman and Andy Baron. They address a lot of the
issues you will face in the conversion from an Access
developers perspective.
-Sue
On 30 Oct 2006 07:44:28 -0800, "boborta@.hotmail.com"
<boborta@.hotmail.com> wrote:

>I have been creating Access applications since version 2.0 and may soon
>become involved with a project that will convert an existing database
>into an ADP. I would consider myself verbose in VBA, but inexperienced
>using a SQL server back end. Typically when faced with a new challenge
>like this one, I will read technical articles & books plus start
>experimenting with code. I am sure there are many of you out there
>that understand the issues I will have to confront (it worked in
>'just' Access, but now...). I would appreciate recommendations
>regarding books, web page links, etc., that will be helpful in my next
>project.
>Access version 2000 - possibly moving to 2003 next year.
>Regards,
>Bob

Converting To ADP, Reference Recommendations

I have been creating Access applications since version 2.0 and may soon
become involved with a project that will convert an existing database
into an ADP. I would consider myself verbose in VBA, but inexperienced
using a SQL server back end. Typically when faced with a new challenge
like this one, I will read technical articles & books plus start
experimenting with code. I am sure there are many of you out there
that understand the issues I will have to confront (it worked in
'just' Access, but now...). I would appreciate recommendations
regarding books, web page links, etc., that will be helpful in my next
project.
Access version 2000 - possibly moving to 2003 next year.
Regards,
Bob<boborta@.hotmail.com> wrote in message
news:1162223068.352845.97040@.i42g2000cwa.googlegroups.com...
> I have been creating Access applications since version 2.0 and may soon
> become involved with a project that will convert an existing database
> into an ADP. I would consider myself verbose in VBA, but inexperienced
> using a SQL server back end. Typically when faced with a new challenge
> like this one, I will read technical articles & books plus start
> experimenting with code. I am sure there are many of you out there
> that understand the issues I will have to confront (it worked in
> 'just' Access, but now...). I would appreciate recommendations
> regarding books, web page links, etc., that will be helpful in my next
> project.
> Access version 2000 - possibly moving to 2003 next year.
> Regards,
Keep in mind that you can use SQL Server as a back-end and continue to use
an access mdb as the front-end. Many developers use this model. You can
still use SQL Server functionality like views, stored procedures, etc.. I
have had difficulties with ADPs and no longer attempt to use them. I also
have questions about the future of ADPs. Others have different views. Google
groups for "access adp pros cons" and you'll see there has been a lot of
discussion on this. Perhaps it has already been decided that this project
will be ADP. If so then good luck.
If the requirement is to move the data to SQL Server but the format of the
front-end is still open I would generally recommend using mdb with linked
tables to SQL Server. A lot would depend on why you are upgrading, the
application itself, the experience of the developers, etc. This is all of
course in my opinion.|||Try the book:
Microsoft Access Developers Guide to SQL Server
by Mary Chipman and Andy Baron. They address a lot of the
issues you will face in the conversion from an Access
developers perspective.
-Sue
On 30 Oct 2006 07:44:28 -0800, "boborta@.hotmail.com"
<boborta@.hotmail.com> wrote:
>I have been creating Access applications since version 2.0 and may soon
>become involved with a project that will convert an existing database
>into an ADP. I would consider myself verbose in VBA, but inexperienced
>using a SQL server back end. Typically when faced with a new challenge
>like this one, I will read technical articles & books plus start
>experimenting with code. I am sure there are many of you out there
>that understand the issues I will have to confront (it worked in
>'just' Access, but now...). I would appreciate recommendations
>regarding books, web page links, etc., that will be helpful in my next
>project.
>Access version 2000 - possibly moving to 2003 next year.
>Regards,
>Bob

Sunday, February 12, 2012

Converting RS 2000 Project to RS 2005

I finally got a virtual machine setup with Server 2003, SQL 2005 Feb 2005
CTP, and VS 2005 Feb 2005 CTP. Backed up the database that I used in VS 2003
for my RS 2000 project and restored it in SQL 2005 (no issues with that).
Then I opened up the RS 2000 project in VS 2005 and it brought up a wizard to
convert the solution into VS 2005 format. Once that was complete the layout
view for the report looked fine and all of the datasets were pulling back the
proper data.
Whenever I try to preview or build the solution the following error is
displayed:
Cannot call Invoke or BeginInvoke on a control until the window handle has
been created.
Not sure what this means or what I need to do to fix it. I have verified
that RS 2005 is up and running correctly by running some of the
AdventureWorks samples in the Report Manager.
Hopefully this is not a sign on how difficult it will be to move RS 2000
projects over to RS 2005.I wouldn't worry. You still have an early beta.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"b5lurker" <b5lurker@.discussions.microsoft.com> wrote in message
news:E1C0B26F-912B-458B-8E19-DB87D99A33F6@.microsoft.com...
> I finally got a virtual machine setup with Server 2003, SQL 2005 Feb 2005
> CTP, and VS 2005 Feb 2005 CTP. Backed up the database that I used in VS
2003
> for my RS 2000 project and restored it in SQL 2005 (no issues with that).
> Then I opened up the RS 2000 project in VS 2005 and it brought up a wizard
to
> convert the solution into VS 2005 format. Once that was complete the
layout
> view for the report looked fine and all of the datasets were pulling back
the
> proper data.
> Whenever I try to preview or build the solution the following error is
> displayed:
> Cannot call Invoke or BeginInvoke on a control until the window handle has
> been created.
> Not sure what this means or what I need to do to fix it. I have verified
> that RS 2005 is up and running correctly by running some of the
> AdventureWorks samples in the Report Manager.
> Hopefully this is not a sign on how difficult it will be to move RS 2000
> projects over to RS 2005.|||On Thu, 31 Mar 2005 10:41:10 -0800, "b5lurker"
<b5lurker@.discussions.microsoft.com> wrote:
>I finally got a virtual machine setup with Server 2003, SQL 2005 Feb 2005
>CTP, and VS 2005 Feb 2005 CTP. Backed up the database that I used in VS 2003
>for my RS 2000 project and restored it in SQL 2005 (no issues with that).
>Then I opened up the RS 2000 project in VS 2005 and it brought up a wizard to
>convert the solution into VS 2005 format. Once that was complete the layout
>view for the report looked fine and all of the datasets were pulling back the
>proper data.
>Whenever I try to preview or build the solution the following error is
>displayed:
>Cannot call Invoke or BeginInvoke on a control until the window handle has
>been created.
>Not sure what this means or what I need to do to fix it. I have verified
>that RS 2005 is up and running correctly by running some of the
>AdventureWorks samples in the Report Manager.
>Hopefully this is not a sign on how difficult it will be to move RS 2000
>projects over to RS 2005.
Specific Reporting Services 2005 questions are probably best asked on
the microsoft.private.sqlserver2005.reportingsvcs newsgroup, meantime.
Despite the group's name, it's open to the public.
Andrew Watt
MVP - InfoPath|||Andrew Watt [MVP - InfoPath] wrote:
> Specific Reporting Services 2005 questions are probably best asked on
> the microsoft.private.sqlserver2005.reportingsvcs newsgroup, meantime.
> Despite the group's name, it's open to the public.
Prove the existence of this so-called private newsgroup "open to the public"
that you have a propensity for mentioning by providing an actually link to it.
TIA,
GeoSynch|||http://communities.microsoft.com/newsgroups/default.asp?icp=sqlserver2005&slcid=us
"GeoSynch" wrote:
> Andrew Watt [MVP - InfoPath] wrote:
> > Specific Reporting Services 2005 questions are probably best asked on
> > the microsoft.private.sqlserver2005.reportingsvcs newsgroup, meantime.
> > Despite the group's name, it's open to the public.
> Prove the existence of this so-called private newsgroup "open to the public"
> that you have a propensity for mentioning by providing an actually link to it.
> TIA,
> GeoSynch
>
>|||Thanks. I had searched MSDN and Google for it without luck.
"MJ Taft" <MJTaft@.discussions.microsoft.com> wrote in message
news:30B98187-E4C2-484B-84C7-9A9FA70AECB3@.microsoft.com...
> http://communities.microsoft.com/newsgroups/default.asp?icp=sqlserver2005&slcid=us
> "GeoSynch" wrote:
>> Andrew Watt [MVP - InfoPath] wrote:
>> > Specific Reporting Services 2005 questions are probably best asked on
>> > the microsoft.private.sqlserver2005.reportingsvcs newsgroup, meantime.
>> > Despite the group's name, it's open to the public.
>> Prove the existence of this so-called private newsgroup "open to the public"
>> that you have a propensity for mentioning by providing an actually link to
>> it.
>> TIA,
>> GeoSynch
>>