Populate default row in ASP.Net RDLC Report using C# and VB.Net

Vanessa
 
on Mar 30, 2022 01:28 AM
Sample_355591.zip
859 Views

Hi!

Can anyone help me to insert data on default rows and columns using APS.Net and SQL Database and display data on RDLC Report Output.

I have a table in sql database, what I want is create a report using RDLC Report with default rows and column using insert statement.

Example.

Colunms are:  Product ID      Product Name     Price

Default Rows are:  Product ID = PID00      

then Product Name and Price are blank becuse I what to use insert statement using sql instead of update statement

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Apr 11, 2022 05:21 AM

Hi Vanessa,

Refer below example created using below article.

RDLC (Local SSRS) Report ASP.Net Example using DataSet or DataTable in C# VB.Net and Visual Studio 2010

HTML

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
</rsweb:ReportViewer>

Namespaces

C#

using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;

VB.Net

Imports System.Configuration
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        Customers dsCustomers = GetData("select top 1 CustomerId,ContactName,City,Country from customers");
        ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
    }
}

private Customers GetData(string query)
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;

            sda.SelectCommand = cmd;
            using (Customers dsCustomers = new Customers())
            {
                sda.Fill(dsCustomers, "DataTable1");
                dsCustomers.Tables["DataTable1"].Rows[0]["CustomerId"] = "PID00";
                dsCustomers.Tables["DataTable1"].Rows[0]["ContactName"] = string.Empty;
                dsCustomers.Tables["DataTable1"].Rows[0]["City"] = string.Empty;
                dsCustomers.Tables["DataTable1"].Rows[0]["Country"] = string.Empty;
                return dsCustomers;
            }
        }
    }
}

VB.Net

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
        Dim dsCustomers As Customers = GetData("select top 1 CustomerId,ContactName,City,Country from customers")
        Dim datasource As New ReportDataSource("Customers", dsCustomers.Tables(0))
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(datasource)
    End If
End Sub

Private Function GetData(query As String) As Customers
    Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Dim cmd As New SqlCommand(query)
    Using con As New SqlConnection(conString)
        Using sda As New SqlDataAdapter()
            cmd.Connection = con

            sda.SelectCommand = cmd
            Using dsCustomers As New Customers()
                sda.Fill(dsCustomers, "DataTable1")
                dsCustomers.Tables("DataTable1").Rows(0)("CustomerId") = "PID00"
                dsCustomers.Tables("DataTable1").Rows(0)("ContactName") = String.Empty
                dsCustomers.Tables("DataTable1").Rows(0)("City") = String.Empty
                dsCustomers.Tables("DataTable1").Rows(0)("Country") = String.Empty
                Return dsCustomers
            End Using
        End Using
    End Using
End Function

Screenshot