|
there are a few ways you could do this.
you could select the data that you wish to display out of your current data source and copy it to a different dataset with the same structure. then set the datasource of the report = the dataset with just the single row.
or...
you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display.
next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production.
each way has it's +'s and -'s, try them and see which way works out best for yuor particular application.
hope this helps.
-jim
|
|
|
|
|
Jim Matthews wrote:
you could just do everything the way you are currently doing it and create a parameter for the report. in your code you set this parameter = the unique id for the row which yuo wish to display.
next, create a Record Selection Formula and have it select only the rows which match the parameter value. i used this method when i designed our company's new packing slip that we are now using in production.
I would like to do it the way explained above. Do you have any examples of this?
In my database, the primary key is an autonumber named contactID. Is it possible to pass that value to the report and use it in the record selection formula? That sounds simple to do but don't know how to start it.
Thanks again
Beginner in ASP.Net and VB.Net
|
|
|
|
|
no problem.
i actually should have provided some source code here as the crystal objects are not very intuitive. (imho)
1. in your report create a parameter field called "ContactId"
2. in your report right click an empty area in the field explorer. go to "Report", then "Selection Formula" and then finally "Records". This should open the formula workshop. enter a formula for selection criteria like the following:
{Contact.ContactId} = {?ContactId}
where Contact is your table name and ContactId is the field which holds your unique constraint.
3. Now what you're going to do is pass the parameter value into the report via code.
'top of your object...
imports CrystalDecisions.CrystalReports.Engine
imports CrystalDecisions.Shared
'load your report
dim myReport as New ReportDocument
with myReport
.Load("myReportTemplate.rpt")
.SetDataSource(myDataSet)
end with
'determine which row you want to display
dim drToDisplay as Datarow = myDataSet.Tables("Client").Select("ClientId = " & cstr(currentClientId))
'get a reference to the reports parameter field
dim prmClientIdParameter as ParameterFieldDefinition
prmClientIdParameter = myReport.DataDefinition.ParameterFields("ClientId")
'create a parameter values collection to set the parameter value
dim valsParClientId as New ParameterValues
'create an instance of a parameter value to add to the above parameter values collection
dim valClientId as New ParameterDiscreteValue
valClientId.Value = drToDisplay("ClientId")
'add the parameter value to the parameters collection
valsParClientId.Add(valClientId)
'set the current value of the reports parameter field
prmClientIdParameter.SetCurrentValues(valsParClientID)
'--- code to display/print report etc ---'
that's pretty much it. watch out for spelling or syntactual errors above as i was typing this off of the top of my head just looking at some of my code. i didn't actually type it into the editor.
another thing to mention is
Brian Bischoff's free online crystal reports e-book.
hope this helps.
-jim
|
|
|
|
|
This all seems like it would work but I have one problem. I am using a form just for the crystalreportviewer. So I don't have access to my dataset. Do I need to create another dataset on this form, or is there a way around it?
Isn't there just a simple way to pass a string, that I already have(contactID), into the report without using the dataset?, then set that string equal to the parameter?, then display that record? I thought all this would be simple coding but it turned out to be a bigger task than I thought. Thanks for that link for the free e-book. I am going to read up on it but I would like to knock out this assignment first.
Thanks again for all your help.
Beginner in ASP.Net and VB.Net
|
|
|
|
|
no problem tim. you could just setup a friend property on your display form and pass in a reference to your report document object.
-jim
|
|
|
|
|
Jim Matthews wrote:
you could just setup a friend property on your display form and pass in a reference to your report document object
Sorry to be such a pain but could you show me how do to this?
Thanks so much for all your help and knowledge
Beginner in ASP.Net and VB.Net
|
|
|
|
|
Thanks Jim,
I downloaded the e-book that you recommended and found some great information on what I was looking for. I knew there was something simple I could do. Here is what I did.
I created a reportdocument from the toolbox under components and named it report1. I then added this code to my form load event.
Report1.DataDefinition.RecordSelectionFormula = "{MYTABLE.CONTACTID} =" & frmMain.strContactID
CrystalReportViewer1.ReportSource = Report1 This works perfect.
Thanks again for all your help and support;)
Beginner in ASP.Net and VB.Net
|
|
|
|
|
no problem tim.
take it easy.
-jim
|
|
|
|
|
Hey,
I have a treeview in my vb.net application. when i change the name of my treenode i am trying to reflect the change in my xml document and then repopulate the tree.
<category>
<name>Data To be Updated</name>
</category>
I can populate tree view, and rename the tree node but am unable to reflect the change in the xml
Any help would be greatly appreciated i have tried looking at examples but and unable to get anywhere.
thanks for any help in advance
|
|
|
|
|
How is your Treeview bound to the XML? Is it through a DataSet or is the TreeView just loading it from the .XML file directly?
The only way you can do something like this is if your Treeview is bound to a DataSet version of the XML file. When the data is changed in the Treeview, the DataSet can be updated. When the changes are complete, the DataSet can export back to an XML file. The Treeview control CANNOT do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey,
I populate my tree using a recursive function to load hte xml file, and can add nodes to the tree which update the xml file using MSXML. Can i use MSXML to update the data between tags in the XML file:
<category>
<name>Data To be Updated</name>
</category>
(the tree node names) based on the selected tree node being renamed using the AfterLabelEdit command?
Thanks for the help
Chris
|
|
|
|
|
Well, since the TreeView control doesn't support Data Binding, you'll either have to add that support by creating a custom TreeView control or use a similar procedure to write the data back out that you used to get it into the TreeView.
You'll have to do some extra research on these methods to see what's going to work the best for your situation and requirements.
You might want to take a look at Extending the TreeView Control[^] on MSDN for a how-to on adding Data Binding.
When you rename a node in the Tree, the TreeView will fire a couple of events. You use the source data to find the appropriate node in the DataSet and update the data in the DataSet. Now, when your done, the DataSet object can write the resulting XML file back out for you. You won't have to iterate through the nodes and write eash one out by hand. That's why I highly suggest you use a DataSet object for your Tree data source.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for your input, appreciate it.
I have managed to load the xml file in to a dataset before, but was unable to make the treeview use this dataset.
I will read that article and let you know how i get on.
Thanks again
Chris
|
|
|
|
|
Hey Dave,
I have written a function that can update the xml file using a DataSet.
My problem is I call this function in the AfterLabelEdit method and it runs.
But it updates the old name with the old name! as i cannot catch the new name that is typed in to the selected treenode until the AfterLabelEdit method as finished.
Do you have any suggestions of how to get the newly type name so when enter is pressed and the AfterLabelEdit method is run the new name can be used to update the old one using the update dataset function.
Thanks you for your help
Chris
|
|
|
|
|
What's the code in the event handler? Are you using the .Text property of the e.Node object that's passed to the handler? You will get the Node that was edited in the e.Node object AND you will get the new label text in the e.Label object.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey,
Cheers again for the help, i have used a timer and made the AfterSelectEvent fire that. But will be changing my treenode to use a real dir structure soon, so i will keep that in mind thankyou.
Another question is that i am now using DSOFile to load MS Office file properties in to the form when the file node of my tree is double clicked.
This works and loads the file properties in to the form first time the node is double clicked, but if you try to go back to that file an error occurs saying that it cannot load the file properties because the file is open.
Is there anyway to close the file as soon as the properties have been retrieved?
Thank you for all your help
Chris
|
|
|
|
|
You can force the release of the underlying COM object by using Marshal.ReleaseComObject() on the instance of the DSO object you created. Try this:
Imports System.Runtime.Interop
.
.
.
' I'm assuming you're using the PropertyReadClass...
Dim dso As New DSOleFile.PropertyReaderClass
'
' Do whatever you need to with the object here...
'
' Now, release the unmanaged object and it's underlying resources.
Marshal.ReleaseComObject(dso)
' Drop our managed reference to the object.
dso = Nothing
.
.
.
And let the garbage collector do the rest...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey,
Thanks for the reply. I have tried using the Marshal.ReleaseComObject but it does not seem to close the file, giving the error 'The file is open and cannot be read'. I have used hte import of InteropServices too.
my code is:
<br />
'DSO Properties<br />
Dim oDsoPropReader As DSOleFile.PropertyReader = New DSOleFile.PropertyReaderClass<br />
Dim oDsoFileProp As DSOleFile.DocumentProperties<br />
<br />
oDsoFileProp = oDsoPropReader.GetDocumentProperties(strFullPath) '<-- This line causes the error<br />
<br />
tbAuthor.Text = oDsoFileProp.Author<br />
tbFormat.Text = oDsoFileProp.AppName<br />
lblDateCreated.Text = oDsoFileProp.DateCreated<br />
lblDateModfied.Text = oDsoFileProp.DateLastSaved<br />
<br />
Marshal.ReleaseComObject(oDsoPropReader)<br />
<br />
oDsoFileProp = Nothing<br />
oDsoPropReader = Nothing<br />
Is my code wrong?, this help is really appreciated.
Chris
|
|
|
|
|
I have solved hte problem i also released the DocumentProperties as well as the reader, thanks for all your help Dave.
Chris
|
|
|
|
|
http://www.thecodeproject.com/vb/net/classinspector.asp[^]
This is a great little tool that can make implementing a snap.
There is a minor bug in the program that truncates some properties.
For instance, the Textbox property _PasswordChar has a default of Chr(0) which is a 'null.' The problem is that the textbox sees a null as an EOF and truncates the string. A simple solution is to remove the null char. To do this, change the line in showEnum and showControlProps from currentText = sb.ToString to read currentText = sb.ToString.Replace(Chr(0), "")
|
|
|
|
|
could anyone tell me why i've got this error message and how i can solve it?
thanks
Server Error in '/Log_In' Application.
--------------------------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 53: Loop
Line 54:
Line 55: DdlNoperiod.Items.AddRange(New Object() {"10", "11", "12", "13"})
Line 56:
Line 57: 'Put user code to initialize the page here
Source File: C:\Inetpub\wwwroot\Log_In\calendar.aspx.vb Line: 55
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Log_In.calendar.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Log_In\calendar.aspx.vb:55
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
|
|
|
|
|
DdlNoperiod.Items.AddRange(New Object() {"10", "11", "12", "13"})
I think DdlNoperiod is DropDownList. You can add only ListItem() to the DropDownList using AddRange method.
Do like this.
DdlNoperiod.Items.AddRange(New Object() {new ListItem("10"), new ListItem("11"), new ListItem("12"), new ListItem("13") })
|
|
|
|
|
unfortunately, it doesn't work by that way.
|
|
|
|
|
I have a function that I need to convert from C# to VB.
C#
public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}
My VB So far...
Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While ((b1 = theStream.ReadByte()) <> -1)
tempStream.WriteByte(((byte)b1))
End While
Return tempStream.ToArray()
End Function
i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement.
Please can someone help me to convert the function
Thank You
|
|
|
|
|
You have only one error in the line tempStream.WriteByte(((byte)b1)) . The VB equivelent of (byte)b1 is CType(b1, Byte) .
The full VB code should be
Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While Not ((b1 = theStream.ReadByte) = -1)
tempStream.WriteByte(CType(b1, Byte))
End While
Return tempStream.ToArray
End Function
|
|
|
|