Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dears if i am using vb.net what the code using instead of this:
C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;
using Microsoft.Reporting.WebForms;

public partial class ReportViewerLocalMode : System.Web.UI.Page
{
    public string thisConnectionString = 
       ConfigurationManager.ConnectionStrings[
       "NorthwindConnectionString"].ConnectionString;

    /*I used the following statement to show if you have multiple 
      input parameters, declare the parameter with the number 
      of parameters in your application, ex. New SqlParameter[4]; */

    public SqlParameter[] SearchValue = new SqlParameter[1];

    protected void RunReportButton_Click(object sender, EventArgs e)
    {
        //ReportViewer1.Visible is set to false in design mode
        ReportViewer1.Visible = true;
        SqlConnection thisConnection = new SqlConnection(thisConnectionString);
        System.Data.DataSet thisDataSet = new System.Data.DataSet();       
        SearchValue[0] = new SqlParameter("@CategoryName", 
                         DropDownList1.SelectedValue);

        /* Put the stored procedure result into a dataset */
        thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
                      "ShowProductByCategory", SearchValue);

        /*or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
               "ShowProductByCategory", dropdownlist1.selectedvalue); 
               if you only have 1 input parameter  */

        /* Associate thisDataSet  (now loaded with the stored 
           procedure result) with the  ReportViewer datasource */
        ReportDataSource datasource = new 
          ReportDataSource("DataSetProducts_ShowProductByCategory", 
          thisDataSet.Tables[0]);

        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
        if (thisDataSet.Tables[0].Rows.Count == 0)
        {
            lblMessage.Text = "Sorry, no products under this category!";
        }

        ReportViewer1.LocalReport.Refresh();
    }
}

i got a error on sqlhelper
and i put using Microsoft.ApplicationBlocks.Data but it's not define and give error also
thank you
Posted
Updated 6-Jan-13 23:56pm
v3
Comments

If you are looking to convert your code from c# to vb.net you can use some online code conversion utility. Here are a few
http://converter.telerik.com/[^]
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
You may also find this CP article helpful
.NET Code Conversion - Convert your code[^]
 
Share this answer
 
see below code.

VB
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.Reporting.WebForms

Public Partial Class ReportViewerLocalMode
	Inherits System.Web.UI.Page
	Public thisConnectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString

	'I used the following statement to show if you have multiple 
'      input parameters, declare the parameter with the number 
'      of parameters in your application, ex. New SqlParameter[4]; 


	Public SearchValue As SqlParameter() = New SqlParameter(0) {}

	Protected Sub RunReportButton_Click(sender As Object, e As EventArgs)
		'ReportViewer1.Visible is set to false in design mode
		ReportViewer1.Visible = True
		Dim thisConnection As New SqlConnection(thisConnectionString)
		Dim thisDataSet As New System.Data.DataSet()
		SearchValue(0) = New SqlParameter("@CategoryName", DropDownList1.SelectedValue)

		' Put the stored procedure result into a dataset 

		thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue)

		'or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
'               "ShowProductByCategory", dropdownlist1.selectedvalue); 
'               if you only have 1 input parameter  


		' Associate thisDataSet  (now loaded with the stored 
'           procedure result) with the  ReportViewer datasource 

		Dim datasource As New ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables(0))

		ReportViewer1.LocalReport.DataSources.Clear()
		ReportViewer1.LocalReport.DataSources.Add(datasource)
		If thisDataSet.Tables(0).Rows.Count = 0 Then
			lblMessage.Text = "Sorry, no products under this category!"
		End If

		ReportViewer1.LocalReport.Refresh()
	End Sub
End Class
 
Share this answer
 
Comments
ahmad ghader 7-Jan-13 6:22am    
i tried it but i told you:
exist 2 errors :
1- error in namespace:Imports Microsoft.ApplicationBlocks.Data is not define
2- error in sqlhelper(sqlhelper not define) any help please ?
prashant patil 4987 7-Jan-13 6:59am    
hey just check out my new solution 6
thanks but this problem not solved i created a replort with vb.net and i converted the code and got this code:
VB
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.Reporting.WebForms

Partial Public Class Report
    Inherits System.Web.UI.Page
    Public thisConnectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString

    'I used the following statement to show if you have multiple 
    '      input parameters, declare the parameter with the number 
    '      of parameters in your application, ex. New SqlParameter[4]; 


    Public SearchValue As SqlParameter() = New SqlParameter(0) {}

    Protected Sub RunReportButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        'ReportViewer1.Visible is set to false in design mode
        ReportViewer1.Visible = True
        Dim thisConnection As New SqlConnection(thisConnectionString)
        Dim thisDataSet As New System.Data.DataSet()
        SearchValue(0) = New SqlParameter("@CategoryName", DropDownList1.SelectedValue)

        ' Put the stored procedure result into a dataset 

        thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue)

        'or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
        '               "ShowProductByCategory", dropdownlist1.selectedvalue); 
        '               if you only have 1 input parameter  


        ' Associate thisDataSet  (now loaded with the stored 
        '           procedure result) with the  ReportViewer datasource 

        Dim datasource As New ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables(0))

        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(datasource)
        If thisDataSet.Tables(0).Rows.Count = 0 Then
            lblMessage.Text = "Sorry, no products under this category!"
        End If

        ReportViewer1.LocalReport.Refresh()
    End Sub
End Class


and also exist 2 errors :
1- error in namespace:Imports Microsoft.ApplicationBlocks.Data
2- error in sqlhelper(sqlhelper not define) any help please ?
 
Share this answer
 
v3
Comments
ahmad ghader 7-Jan-13 6:05am    
thanks but this problem not solved i created a replort with vb.net and i converted the code and got this code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.Reporting.WebForms

Partial Public Class Report
Inherits System.Web.UI.Page
Public thisConnectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString

'I used the following statement to show if you have multiple
' input parameters, declare the parameter with the number
' of parameters in your application, ex. New SqlParameter[4];


Public SearchValue As SqlParameter() = New SqlParameter(0) {}

Protected Sub RunReportButton_Click(ByVal sender As Object, ByVal e As EventArgs)
'ReportViewer1.Visible is set to false in design mode
ReportViewer1.Visible = True
Dim thisConnection As New SqlConnection(thisConnectionString)
Dim thisDataSet As New System.Data.DataSet()
SearchValue(0) = New SqlParameter("@CategoryName", DropDownList1.SelectedValue)

' Put the stored procedure result into a dataset

thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "ShowProductByCategory", SearchValue)

'or thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
' "ShowProductByCategory", dropdownlist1.selectedvalue);
' if you only have 1 input parameter


' Associate thisDataSet (now loaded with the stored
' procedure result) with the ReportViewer datasource

Dim datasource As New ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables(0))

ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
If thisDataSet.Tables(0).Rows.Count = 0 Then
lblMessage.Text = "Sorry, no products under this category!"
End If

ReportViewer1.LocalReport.Refresh()
End Sub
End Class


and also exist 2 errors :
1- error in namespace:Imports Microsoft.ApplicationBlocks.Data
2- error in sqlhelper(sqlhelper not define) any help please ?
CHill60 7-Jan-13 6:24am    
You will need to add the appropriate reference(s) to the project
Check Underline Code. add into your code..
hope it will helpful for you
VB
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.Reporting.WebForms
 
Public Partial Class ReportViewerLocalMode
	Inherits System.Web.UI.Page
	Public thisConnectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
 
	'I used the following statement to show if you have multiple 
'      input parameters, declare the parameter with the number 
'      of parameters in your application, ex. New SqlParameter[4]; 

 
	Public SearchValue As SqlParameter() = New SqlParameter(0) {}
 
	Protected Sub RunReportButton_Click(sender As Object, e As EventArgs)
		'ReportViewer1.Visible is set to false in design mode
		ReportViewer1.Visible = True
		Dim thisConnection As New SqlConnection(thisConnectionString)
		Dim thisDataSet As New System.Data.DataSet()
                Dim dataadapter as New SqlDataAdpater()
                Dim Cmd as New SqlCommand()
                Cmd .Connection = conn
                Cmd .CommandType = CommandType.StoredProcedure
                Cmd .CommandText = "ShowProductByCategory"
                Cmd .Parameters.Add("@CategoryName", Data.SqlDbType.Varchar)
              Cmd .Parameters("@CategoryName").Value = DropDownList1.SelectedValue
		 
		' Put the stored procedure result into a dataset 
                dataadapter= new SqlDataAdpater(cmd)
                dataadapter.fill(thisDataSet) 
		
		'or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection, 
'               "ShowProductByCategory", dropdownlist1.selectedvalue); 
'               if you only have 1 input parameter  

 
		' Associate thisDataSet  (now loaded with the stored 
'           procedure result) with the  ReportViewer datasource 

		Dim datasource As New ReportDataSource("DataSetProducts_ShowProductByCategory", thisDataSet.Tables(0))
 
		ReportViewer1.LocalReport.DataSources.Clear()
		ReportViewer1.LocalReport.DataSources.Add(datasource)
		If thisDataSet.Tables(0).Rows.Count = 0 Then
			lblMessage.Text = "Sorry, no products under this category!"
		End If
 
		ReportViewer1.LocalReport.Refresh()
	End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900