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 6-Jan-13 23:40pm
Edited 6-Jan-13 23:56pm
v3
Comments
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 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 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 480
1 Tadit Dash 305
2 Sergey Alexandrovich Kryukov 250
3 Peter Leow 190
4 OriginalGriff 163
0 Sergey Alexandrovich Kryukov 9,435
1 OriginalGriff 5,498
2 Peter Leow 4,230
3 Maciej Los 3,540
4 Abhinav S 3,353


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