Changing Sql Connection dynamically in Crystal Reports 10 using DotNet

by Syed Aziz ur Rahman 20. July 2004 01:12


myReport As New crDB()
myReport.SetDatabaseLogon(Me.txtUserId.Text, Me.txtPass.Text, Me.txtServer.Text, Me.txtDB.Text)
Dim myLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

Each myTable In myReport.Database.Tables
   myLogonInfo = myTable.LogOnInfo
   With myLogonInfo.ConnectionInfo
      .ServerName = Me.txtServer.Text
      .DatabaseName = Me.txtDB.Text
      .UserID = Me.txtUserId.Text
      .Password = Me.txtPass.Text
  End With

MessageBox.Show("Login Failed")
   End Try

   'Note: The next line is only necessary for SQL Server
myTable.Location = myTable.Location.Substring(myTable.Location.LastIndexOf(".") + 1)
Next myTable
CrystalReportViewer1.ReportSource = myReport

A very important piece of code is the assignment of the myTable.Location property (near the end of the listing). A requirement for changing the data source of a SQL Server table is that you must also change the Location property of the Table object. The Location property is a string value that has the name of the server as part of the string. It lists the database name, the table owner and the table name. For example, it looks similar to the following:


If you leave the Location property alone and don?t overwrite it, then the report?s server and database name won?t change. Instead, you have to reset it to just the table name. By removing the database name from the string, the report has to look at the new properties you just set to get this information. Consequently, this results in the server and database changing.

The easiest change to make would be to overwrite the Location property with a string constant. For example, the following line of code would overwrite it with the ?Customers? table.

myTable.Location = "Customers"

This works fine if the report only uses one table. But when you have multiple tables, you have to get more creative because you can?t assign the same table name to every table object. Rather than use a string constant, the code parses out the table name from the Location property and reassigns it to itself. This has the effect of resetting the value, but dropping the database name and table owner from the string.

myTable.Location = myTable.Location.Substring(myTable.Location.LastIndexOf(".") + 1)





ASP.Net | DotNet | SqlServer


Java script using in User Control

by Syed Aziz ur Rahman 14. July 2004 03:59

Dear All,
Let me give you an example to explain the usage of javascript in user controls. Let us suppose that u have a usercontrol in which there are 2 textboxes named txt1 and txt2 and a button called btn1 and u want to add some custom checking when the button is clicked.

Make the usercontrol. Put it in a page and see the page in IE. View the source and check the ids of the textboxes and button. You will notice that the ids are "prefixed" by some "ambigous" letters like ctl0:, ctl1 etc.

Asp.net do this prefixing in order to maintain the unique ids of the server controls. Can u think what will happen if there are 2 instance of same user control on a single page? The ids will be like clt0:txt1 and clt1:txt1 for the textbox we named txt1. This is the scenario

So the catch is when u want to use your own javascript, pass the "ClientID" attribute of the textbox to the function. For example the javascript funtion should be like

function ValidateTextBoxes(txt1, txt2)
//do the magic validation

In your code behind u will do like this
btn1.attribute.add("onclik" ."ValidateTextBoxes('" & txt1.ClientID & "'," & txt2.ClientID & "')"). Now u can easily use functions like getElementbyID and dont forget to use the parameters passed in the function.

I know that my writing capabilites is not so good. But i have tried to explain it as good as i can in this short time.

If any problems. email me and i will send you some working sample

Allah Hafiz





Dropdown control overlapping other controls.

by Syed Aziz ur Rahman 13. July 2004 06:59

The behavior of dropdown i.e.overlapping other control was always a poblem for me until i found article. It occurs because the dropdownlists in IE are Windows-rendered controls, not browser-rendered controls. Effectively, all browser-rendered controls go on one layer, and the Windows-rendered controls go on their own, higher layer.

Read this article and enjoy





Powered by BlogEngine.NET
Original Design by Laptop Geek, Adapted by onesoft