Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Dears if i am using vb.net what the code using instead of this:
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 7-Jan-13 0:40am
Edited 7-Jan-13 0:56am
v3
Comments
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

see below 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
 
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
  Permalink  
Comments
ahmad ghader at 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 at 7-Jan-13 6:59am
   
hey just check out my new solution 6
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 ?
  Permalink  
v3
Comments
ahmad ghader at 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 at 7-Jan-13 6:24am
   
You will need to add the appropriate reference(s) to the project
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Check Underline Code. add into your code..
hope it will helpful for you
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 525
1 Maciej Los 319
2 BillWoodruff 174
3 Suraj Sahoo | Coding Passion 170
4 /\jmot 152
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100