Labels

Apache Hadoop (3) ASP.NET (2) AWS S3 (2) Batch Script (3) BigQuery (21) BlobStorage (1) C# (3) Cloudera (1) Command (2) Data Model (3) Data Science (1) Django (1) Docker (1) ETL (7) Google Cloud (5) GPG (2) Hadoop (2) Hive (3) Luigi (1) MDX (21) Mongo (3) MYSQL (3) Pandas (1) Pentaho Data Integration (5) PentahoAdmin (13) Polybase (1) Postgres (1) PPS 2007 (2) Python (13) R Program (1) Redshift (3) SQL 2016 (2) SQL Error Fix (18) SQL Performance (1) SQL2012 (7) SQOOP (1) SSAS (20) SSH (1) SSIS (42) SSRS (17) T-SQL (75) Talend (3) Vagrant (1) Virtual Machine (2) WinSCP (1)

Thursday, June 28, 2012

Use of RequiredFieldValidator and CompareValidator in ASP.NET

RequiredFieldValidator Control: On using this control we can raise an error message when a field in blank or null, i.e., we can define a field as mandatory.

CompareValidator Contro: This control help us to compare value of one field to another field and raise error message based on the condition we defined.

Below is the sample code where we validate StartDate and EndDate for null values using RequiredFieldValidator and compare Startdate with Enddate value using CompareValidator.

<tr>
<td colspan ="6" rowspan ="3" align ="left"><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="StartDatePr" ErrorMessage="Start Date should not be null." Display ="Dynamic"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan ="6" rowspan ="3" align ="left"><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="EndDatePr" ErrorMessage="End Date should not be null." Display ="Dynamic"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan ="6" rowspan ="3" align ="left"><asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="StartDatePr" ControlToValidate="EndDatePr" ErrorMessage="End Date should be greater than Start Date." Operator="GreaterThan" Type="Date" Display ="Dynamic"></asp:CompareValidator></td>
</tr>
</table>


Define Default Value to Date Fields in C Sharp

The below codes populate textboxes (IDs = StartDatePr and EndDatePr) on page load with default values:

protected void Page_Load(object sender, EventArgs e)

{if (!IsPostBack)

{

StartDatePr.Text =
DateTime.Now.AddDays(-30).ToString("MM/dd/yyyy");

EndDatePr.Text = DateTime.Now.ToString("MM/dd/yyyy");

}

}


Wednesday, June 27, 2012

Call SSRS Report in ASP.NET Web Page

The below steps help to call an SSRS report in Web Page designed using ASP.NET. The practice the below code we should install AJAX toolkit.

1. Create a new ASP wep page project.
2. Add a new web form.
3. Add th ebelow scripts in the WEB for designer:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SSRS2.aspx.cs" Inherits="SSRS_WEB.WebForm2" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Start Date: </td>
<td><asp:TextBox Width="180" runat="server" ID="StartDatePr"/></td>
<td><asp:CalendarExtender runat="server" TargetControlID="StartDatePr"/></td>
<td>End Date: </td>
<td><asp:TextBox Width="180" runat="server" ID="EndDatePr"/></td>
<td><asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="EndDatePr"/></td>
<td><asp:Button Text="Show Report" ID="btnSubmit" runat="server" onclick="btnSubmit_Click" /></td>
</tr>
</table>
</div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<rsweb:ReportViewer ID="MyReportViewer" runat="server" Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="800px"
Width="1000px">
<ServerReport ReportServerUrl="" />
</rsweb:ReportViewer>
</form>
</body>
</html>


4. Add below code in respective .CS file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.Common;
using Microsoft.Reporting.WebForms;

namespace SSRS_WEB
{
public partial class WebForm2 : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)

{

}
protected void btnSubmit_Click(object sender, EventArgs e)

{
//First
MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
MyReportViewer.ServerReport.ReportServerUrl = new Uri("
http://localhost/reportserver_Sathya"); // Report Server URL
MyReportViewer.ServerReport.ReportPath = "/SQLSSRS/Dashboard"; // Report Name
MyReportViewer.ShowParameterPrompts = false;
MyReportViewer.ShowPrintButton = false;
ReportParameter[] parameters = new ReportParameter[2];
parameters[0] = new ReportParameter("StartDate", StartDatePr.Text);
parameters[1] = new ReportParameter("EndDate", EndDatePr.Text);
MyReportViewer.ServerReport.SetParameters(parameters);
MyReportViewer.ServerReport.Refresh();



}
}
}


On executing the page, you can see SSRS reoport called in Web page.

Friday, June 8, 2012

Reverse engineer or design a database with Microsoft Visio - Atlanta .NET Regular Guys

Reverse engineer or design a database with Microsoft Visio

How to use Microsoft Visio for Enterprise Architects SP-2 to reverse engineer your database to get nice drawings, and how to turn nice drawings into actual database objects.
Part 1: Reverse Engineer your database

Old database diagram




















First up you simply open Visio and create a new Database Model Diagram
This gives you a database menu option in the menu bar with several helpful commands. There are other database modeling types like ER diagrams and ORM diagrams, but those don’t allow you to make changes to your diagram and update the database or generate new databases later. Now that you have your new, blank document we can use the Reverse Engineer Wizard to connect to a database and generate our drawing automatically. On the menu bar, select DatabaseReverse Engineer to launch the wizard. The first step in the Reverse Engineer Wizard is to use your ODBC data sources to find the database.  If you don’t already have an ODBC connection for your database, you can create a new one inside of the wizard. Use the screenshots at the bottom of this article to guide you through creating a new User Data Source for use with Visio.

New database model diagram











Once you have selected your database connection object, pick which types to reverse engineer (tables, keys, indexes, etc) and then pick the objects you want to reverse engineer. You are first presented with a checkbox list of tables and views followed by a checkbox list of stored procedures. Finally you are given the option to allow the system to add the shapes to the page or to add the shapes manually. I recommend allowing the system to do the work. The last screen you are presented is basically a review of your selections. Click Finish to have the system design the drawing. The resulting drawing will have all the primary keys, foreign keys, relationships, etc. When you click on an object such as a a database table you’ll get the ability to look into the table’s design; column names, indexes, triggers, etc. Here is an example of just such a view.

tables or views to reverse engineertypes to reverse engineer












Database properties









 Part 2: Generate a database from a drawing

Now let’s take a look at things from the other side. In my particular case I felt that I needed to start from scratch to fully redesign my database, so I began with a blank Database Model Diagram and built up each table individually. To design a new table, drag an Entity object from the Shapes toolbox onto the drawing page and modify its database properties as I have done in this screenshot. To create a relationship between two tables, drag a relationship object from the Shapes toolbox onto the drawing page. Drag the arrow end onto the parent table and the other end onto the other table.

New Table






New Relationship







 Visio will attempt to automatically identify the relationship between your tables based on the conceptual names of your tables’ fields.  This example shows just such a relationship

New Relationship with association details












I worked on my table and relationship details until I had this design. I was able to normalize the data, reuse some existing tables, and basically reform the data architecture underneath this application to something that seemed to be a lot more reasonable. Now, with this kind of a table layout, I’m properly positioned to use custom business objects or an OR Mapper like the one from Paul Wilson. The old architecture made that choice difficult if not impossible.
Now that I have my nice new database object design, I want to create these tables. Actually, what I really want is the DDL script I can edit and use in any database to generate these tables. In my case, some of the tables represented in my drawing pre-exist and don’t need to be changed in any way. To do this, I go back to the handy Database menu and select Generate from the list. The first thing that will happen is that the model will be checked for any errors and warnings – things like similar field names with different data types or mismatched relationships. If I have any errors I must fix them first, much like in Visual Studio. 



Promo_NewERD











Once I pass the error checking, I am presented with the Generate Wizard – . The Generate wizard allows me to chose a file location for a DDL script or I can actually have Visio connect to the database engine for me and create a brand new database. Chose to generate the script and click next to get to the database specification portion. Here you can pick which type of database rules you’re going to follow, SQL Server, Access, Oracle, DB2, etc. Pick SQL Server, give your database a name for use in the script and click Next.

GenerateWizard Generate Wizard step 2 





You will be presented with a review of everything you are about to export.  Press next to do an automatic physical review of your model against that database’s rules.  Once the validation is completed you can press Finish to generate the DDL file.  Even though you might not have selected to generate the new database, you might be presented with a SQL Server Create Database dialog.  Click Close on this dialog to get to the option to view the generated DDL script in the Visio code editor.  Here is a screenshot of that generated code:

 CodeEditor

Now that you have this code file you can modify it and run it in query analyzer (yes – I’m still running SQL 2000) against any database you like.  The best part is that you can use a tool like Visio to maintain your database.  You can easily reverse engineer a subset of tables in a database, check on relationships, etc.  You can make modifications and persist those changes back to the database.  This is an easy way to learn about your database at a glance.  There is an Update command on the Visio database menu that I didn’t go into.  This command allows you do generate change scripts, detect differences, log errors, etc.  All in all, Visio can be an important tool in your toolbox.

Sunday, June 3, 2012

How to get customized color in SSRS chart

While we design SSRS chart, we have to use available colors from SSRS Color pallette or color templates by selecting them from color, background color, etc. Instead we can apply our own defined colors to our chart by following below steps:

Step 1: Create new SSRS report.

Step 2: Go to Report properties of the SSRS report. Open Code section and copy-paste the below code in the Code area:

Private colorPalette As String() = { "Blue", "Red", "Teal", "Gold", "Green","#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}

Private count As Integer = 0

Private mapping As New System.Collections.Hashtable()

Public Function GetColor(ByVal groupingValue As String) As String

If mapping.ContainsKey(groupingValue) Then

Return mapping(groupingValue)

End If

Dim c As String = colorPalette(count Mod colorPalette.Length)

count = count + 1

mapping.Add(groupingValue, c)

Return c

End Function







 





















Step 3: Now create a chart (e.g., pie chart); Open Series properties, in Fill expression copy-paste below command:

=code.GetColor(Fields!SalesMonth.Value)


Step 4 (Option): You can use this color in your grid report as a background, by copy-paste the below code in Columns Background properties:

=code.GetColor(Fields!SalesMonth.Value)

The output will be simillar to one below:



Friday, June 1, 2012

Get Hierarchial Level of Employee Using SQL

Create a new table as below:

 CREATE TABLE [dbo].[Employee](
                    [EmployeeID] [int] NOT NULL,
                    [EmpName] [varchar](100) NULL,
                    [Department] [varchar](100) NULL,
                    [Designation] [varchar](100) NULL,
                    [Salary] [money] NULL,
                    [ManagerID] [int] NULL
    ) ON [PRIMARY]


Insert valuse to the table:

SELECT L3.EmpName AS LEVEL2, L2.EmpName LEVEL1, L1.EmpName LEVEL0
    ,CAST(ISNULL(L3.EmployeeID,'') AS VARCHAR(5))+'/' + CAST(ISNULL(L2.EmployeeID,'') AS VARCHAR(5))+'/' + CAST(ISNULL(L1.EmployeeID,'') AS VARCHAR(5)) AS LEVELPATH
,CAST(ISNULL(L3.EmpName,'') AS VARCHAR(5))+'/' + CAST(ISNULL(L2.EmpName,'') AS VARCHAR(5))+'/' + CAST(ISNULL(L1.EmpName,'') AS VARCHAR(5)) AS EMPLOYETREE
FROM Employee L1
LEFT JOIN Employee L2 ON L1.ManagerID = L2.EmployeeID
LEFT JOIN Employee L3 ON L2.ManagerID = L3.EmployeeID
LEFT JOIN Employee L4 ON L3.ManagerID = L4.EmployeeID
LEFT JOIN Employee L5 ON L4.ManagerID = L5.EmployeeID