This is a migrated thread and some comments may be shown as answers.

sql parameter pass

12 Answers 431 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
rgf21
Top achievements
Rank 1
rgf21 asked on 30 May 2007, 10:41 AM
Hi. I have a radMultiPage and I want to pass a value of a label to a ReportViwer inside the radMultiPage to use in a sql select.
I Have this:
Me.sqlSelectCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@user_id", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, FalseCType(0, Byte), CType(0, Byte), "user_id", System.Data.DataRowVersion.Current, "aaa")}) 

But I want to put the value of the label where the "aaa" is. Inside my report.vb I don't have access to the label...

Any help please?

Thanks!

12 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 30 May 2007, 05:00 PM
Hi rgf21,

It is normal that you cannot access the label from inside the Report directly because this behavior is by design. But there are several of approaches you can use.  For example you can pass the label's to the report through its constructor

Public Class Report1
    Inherits Report
   
    Public Sub New(ByVal userID As String)
        '
        ' Required for Telerik Reporting designer support
        '
        InitializeComponent()

        '
        ' TODO: Add any constructor code after InitializeComponent call
        '
       
        Me.sqlSelectCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@user_id", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "user_id", System.Data.DataRowVersion.Current, userID)})
    End Sub
   
End Class 


Another possible solution is to prepare the report's data source from outside the report and pass it -- the Report.DataSource and Report.DataMember are public properties that you can use from outside.

 
Kind regards,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rgf21
Top achievements
Rank 1
answered on 04 Jun 2007, 11:56 AM
Thanks Svetoslav. Your snd solution worked just fine. Now I have another problem. When I try to use this:
Me.textBox4.Value = "=data_nascimento" 
I get in the report "=data_nascimento" and I should get "1-1-2000". For the other fields od the DB it's working. Only the datetime ones aren't working.... (the name of the field is correct)

Can you help me?

Thanks again!
0
Svetoslav
Telerik team
answered on 04 Jun 2007, 04:00 PM
Hello rgf21,

We will need some more information about the DateTime problem:
  1. Can you please explain in detail how exactly the DateTime fields are not working?
  2. Do you receive an error message/exception? If yes, please give us details on what the error says.
  3. If the report is rendered OK, what text is rendered from this TextBox instead of "1-1-2000"?
  4. Please verify that the exact type of the data field is DateTime.

You can format the value of a TextBox item using its Format property. Provide format string as you're using the String.Format() method. For example, to display the long string representation of the DateTime field you can use the next format string:

dateTextBox.Format = "{0:D}"

We recommend you to download and install the latest Service Pack 1 of the Telerik Reporting - v1.1. We made several tests with different format strings and data (including DBNull-s) and as of now we haven't got any problems.

 
Kind regards,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rgf21
Top achievements
Rank 1
answered on 04 Jun 2007, 04:22 PM
  1. I can't get the results that are stored in the DB. The varchar fields work fine.
  2. No. No error messages
  3. Everything is rendered OK, except the text of TextBox4. The text  showed  is "=data_dascimento" (exactly the name of the field I want to get the data from.
  4. It's a datetime of SQL Server 2005...
0
Svetoslav
Telerik team
answered on 05 Jun 2007, 11:54 AM
Hi rgf21,

Please verify whether the value of TextBox4 starts with one or more white spaces before the '=' character.

The TextBox binding works this way: 
  • if the Value is string it checks the 1st character for the '=' - if it starts with '=' this string is interpreted as a binding expression; otherwise it is rendered as is
  • if the Value is other than a string object (and not null/Nothing) - the result of Value.ToString() is displayed.

From the additional info you have sent it seems that the Value is not processed as a binding expression so I suppose that there is a leading space that you should delete.
 

Best wishes,

Svetoslav

the Telerik team


Instantly find answers to your questions at the new Telerik Support Center
0
rgf21
Top achievements
Rank 1
answered on 05 Jun 2007, 03:10 PM
Hi,

the value of TextBox4 doesn't start with one or more white spaces before the '=' character, but I solved my problem installing SP1.

Thanks for the help.
0
Tim Black
Top achievements
Rank 1
answered on 14 Aug 2007, 08:59 PM
How do I create an instance of a report in the reportviewer in the VB code-behind with a constructor that accepts a parameter?

Public Sub New(ByVal userID As String)
... code
End Sub


Thanks
0
Svetoslav
Telerik team
answered on 15 Aug 2007, 08:10 AM
Hello Tim Black,

The only way to use a report with constructor with parameters is to create it by yourself and to pass it to the report viewer. The reason is that the VisualStudio designer and the default code generation algorithm know only how to use the default constructor for a class that has no parameters , which is not your case.

 
Regards,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tim Black
Top achievements
Rank 1
answered on 15 Aug 2007, 01:09 PM
Hi Svetoslav,

Thanks for the quick response!!

I know how to create the constructor that accepts an input value, but what code would I use in the viewer to call the constructor with an input value?

0
Svetoslav
Telerik team
answered on 16 Aug 2007, 11:32 AM
Hello Tim Black,

You have to instantiate the report class in exactly the same way as you would do with any other class, and then pass the instance to the report viewer:

Dim userID as Integer = 123
reportViewer1.Report = new MyReport(userID)


 
All the best,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tim Black
Top achievements
Rank 1
answered on 16 Aug 2007, 01:54 PM
My confusion comes from trying to add an input parameter to the example instantiation in your code:


Dim reportName As String = "AppReport, App_Code.86ajnlir, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"

Dim reportType As Type = Type.[GetType](reportName)

Dim report As Report = DirectCast(Activator.CreateInstance(reportType), Report)

Me.vwrMain.Report = report

Me.Page.Title = "telerik Report Viewer - " + reportType.Name

0
Chavdar
Telerik team
answered on 16 Aug 2007, 05:05 PM
Hi Tim,

You can use another overload of the CreateInstance method of the Activator class to achieve the desired result. To learn more about the Activator class you can take a glance at the following article.

 
Sincerely yours,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
rgf21
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
rgf21
Top achievements
Rank 1
Tim Black
Top achievements
Rank 1
Chavdar
Telerik team
Share this question
or