Wednesday, March 17, 2010

ADO.NET & Common Code for Connection in VB.NET

ADO.NET was designed to meet the needs of this new programming model: disconnected data architecture, tight integration with XML, common data representation with the ability to combine data from multiple and varied data sources, and optimized facilities for interacting with a database, all native to the .NET Framework.

ADO.NET Components:

ADO.NET Components have been designed to factor data access for data manipulation. There are two central components of ADO.NET that accomplish this is

Dataset &

Data Provider

Connection

Command

DataReader

DataAdapter

All the 4 under Data Provider are Data Provider Objects

ADO.NET DataSet: is the core component of the disconnected architecture of ADO.NET. The DataSet is explicitly designed for data access independent of any data source. As a result it can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. The DataSet contains a collection of one or more DataTable objects made up of rows and columns of data, as well as primary key, foreign key, constraint, and relation information about the data in the DataTable objects.

The other core element of the ADO.NET architecture is the, .NET Framework Data Provider whose components are explicitly designed for data manipulation and fast, forward-only, read-only access to data. The Connection object provides connectivity to a data source. The Command object enables access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information. The DataReader provides a high-performance stream of data from the data source. Finally, the DataAdapter provides the bridge between the DataSet object and the data source. The DataAdapter uses Command objects to execute SQL commands at the data source to both load the DataSet with data, and reconcile changes made to the data in the DataSet back to the data source.

You can write .NET Framework data providers for any data source. The .NET Framework ships with two .NET Framework data providers: the .NET Framework Data Provider for SQL Server and the .NET Framework Data Provider for OLE DB.

VB.NET Code

Imports System.Data.SqlClient

Dim SqlConn As New SqlConnection()

Dim SqlComnd As New SqlCommand()

Dim Sqldr As SqlDataReader

SqlConn.ConnectionString = "DataSource=localhost;Initial Catalog=Audit.mdf;Integrated Security=SSPI;"

SqlConn.Open()

SqlComnd.Connection = SqlConn

SqlComnd.CommandText = "Select * From Employee"

Sqldr = SqlComnd.ExecuteReader


While Sqldr.Read()

End While


Sqldr.Close()

SqlConn.Close()

Monday, February 22, 2010

Compare Two Excel Sheets Programatically in C#

Hi All, Here I am Posting a Application which compares two excel sheets to show the differences like which row has been updated, deleted and inserted.(Assume I have two excel files one generated yesterday and other one generated today with some updates, deletions and insertions ) to find out new changes here is the program

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using System.IO;
using System.Data.OleDb;
using Excel = Microsoft.Office.Interop.Excel;

namespace CompareExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void BtnBrws1_Click(object sender, EventArgs e)
{
OpenFileDialog DialogA = new OpenFileDialog();
DialogA.CheckFileExists = true;
//DialogA.InitialDirectory = "Desktop"
DialogA.Title = "Select a File";

if (DialogA.ShowDialog() == DialogResult.OK)
{
FileTxt1.Text = DialogA.FileName;
}
else if(FileTxt1.Text =="")
{
MessageBox.Show("Please Select a File");
}

}

private void BtnBrws2_Click(object sender, EventArgs e)
{
OpenFileDialog DialogB = new OpenFileDialog();
DialogB.CheckFileExists = true;
DialogB.Title = "Select a file";
if (DialogB.ShowDialog() == DialogResult.OK)
{
FileTxt2.Text = DialogB.FileName;
}
else if(FileTxt2.Text == "")
{
MessageBox.Show("Please Select a File");
}

}

private void BtnCmpr_Click(object sender, EventArgs e)
{
string filename1 = FileTxt1.Text;
string filename2 = FileTxt2.Text;

//MessageBox.Show(filename1);
//MessageBox.Show(filename2);

string file1_sheet = GetExcelSheets(filename1);
string file2_sheet = GetExcelSheets(filename2);


// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString1 = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + filename1 + ";" +
"Extended Properties=Excel 12.0;";

String sConnectionString2 = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + filename2 + ";" +
"Extended Properties=Excel 12.0;";


// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString1);

// Open connection with the database.
objConn.Open();

// The code to follow uses a SQL SELECT command to display the data from the worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + file1_sheet + "$]", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

DataTable dt1 = objDataset1.Tables[0];
//dt1.DefaultView.Sort = string.Format("{0} {1}", "id", "ASC");

//MessageBox.Show("" + GridView1.Rows.Count);

// Clean up objects.
objConn.Close();

objConn = new OleDbConnection(sConnectionString2);

// Open connection with the database.
objConn.Open();

// The code to follow uses a SQL SELECT command to display the data from the worksheet.

// Create new OleDbCommand to return data from worksheet.
objCmdSelect = new OleDbCommand("SELECT * FROM [" + file2_sheet + "$]", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
objDataset1 = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

DataTable dt2 = objDataset1.Tables[0];
//dt2.DefaultView.Sort = string.Format("{0} {1}", "id", "ASC");

// Clean up objects.
objConn.Close();

//GridView1.DataSource = dt2;
//GridView1.DataBind();

DataRow[] rows1 = dt1.Select("", "id ASC");
DataRow[] rows2 = dt2.Select("", "id ASC");

DataRow datarow1, datarow2;
int i, j;
for (i = 0, j = 0; i < dt1.Rows.Count; i++)
{
datarow1 = rows1[i];
string column1 = datarow1[0].ToString().Trim();

datarow2 = rows2[j];
string column2 = datarow2[0].ToString().Trim();

if (column1.CompareTo(column2) == 0)
{
int n;
for (n = 1; n < datarow1.ItemArray.Length; n++)
{
string value1 = datarow1.ItemArray[n].ToString().Trim();
string value2 = datarow2.ItemArray[n].ToString().Trim();
if (value1.CompareTo(value2) != 0)
{
MessageBox.Show("Updated Row : " + column1);

break;
}
}
j++;
}
else if (column1.CompareTo(column2) < 0)
{
MessageBox.Show("Deleted Row : " + column1);

}
}
for (i = j; i < rows2.Length; i++)
{
datarow2 = rows2[i];
MessageBox.Show("Inserted Row :" + datarow2[0].ToString());
}

}

public string GetExcelSheets(string excelFileName)
{
Microsoft.Office.Interop.Excel.Application excelFileObject = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workBookObject = null;
workBookObject = excelFileObject.Workbooks.Open(excelFileName, 0, true, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
"",
true,
false,
0,
true,
false,
false);
Excel.Sheets sheets = workBookObject.Worksheets;

// get the first and only worksheet from the collection of worksheets
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
MessageBox.Show(worksheet.Name);
return worksheet.Name;
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

Monday, February 15, 2010

WPF Vs Silverlight

This is a question that they ask me regularly: What is the difference between the Windows Presentation Foundation (WPF) and Silverlight, and in what scenarios does it make sense to use each?

Microsoft feels that user experience is important, and invested in multiple technologies to promote better user experience. Both WPF and Silverlight use XAML (Extensible Application Markup Language) under the covers.

Let's look at some of the different characteristics of each technology:

WPF:
Ships as part of the .NET Framework (version 3.0 and onward)
Runs as Windows application or as web "browser application" (called XBAP, for "XAML Browser Application"). Note that XBAPs run only in Internet Explorer with .NET 3.0 and in both Internet Explorer and Firefox with .NET 3.5.
Runs on Windows machines only (Windows XP, Windows Server 2003, Windows Vista, and Windows Server 2008)
Richest functionality, including 3D graphics

Silverlight:
Ships independently
Runs in web browsers only (Internet Explorer, Firefox, Safari)
Runs on Windows or Mac operating systems (also on Linux via Moonlight, which is an open source implementation of Silverlight based on Mono)
Functionality is a subset of WPF's feature set


When should you use each? The maddening answer is (of course): it depends!

WPF is a more mature technology and was designed with a richer feature set. It also has the advantage of being able to run in a browser or as an installed Windows-Form-type app.

Silverlight has a broader reach. You can access Silverlight from many operating systems and web browsers.

The most important reason to choose one over the other should be based on the intended audience for the application. For example, if a corporation is designing an application for internal use only and every employee has Windows XP as the company standard OS, then go with WPF to leverage the richer feature set. If a corporation is designing an external-facing website, then Silverlight is the better choice because potential customers can access the website from a variety of different operating systems and browsers.

Wednesday, July 15, 2009

ASP.NET 2.0 Features and Differences Between ASP.NET 2.0, 3.0, & 3.5

ASP.NET:-

ASP.NET 2.0 introduces a lot of new features. Some of this features aim to simplify the problems faced using the earlier versions and some features are introduced to provide lot of new facilities. The most important features that are incorporated in ASP.NET 2.0 are:

(a)Master Pages

Master pages are introduced to remove one of the most important deficiencies of earlier version of ASP.NET. One thing that has become apparent in the earlier version of ASP.NET is the lack of architecture for applying a consistent look and feel. In earlier version of ASP.NET whenever a developer wants to replicate a common functionality of a web page in other pages, the most possible options he uses is creating a user control and then replicate the functionality in other pages.

ASP.NET 2.0 aims to solve this problem by introducing the concept of Master pages. First the developer needs to define a master page containing the content that he wants to appear on other pages and then use the Content Placeholder controls to define the locations where the sub pages can plug in the content of their own. The he has to build the sub pages - .aspx pages – that reference the master using directives like this one:

<%@Page MasterPageFile = ~/MyMasterPage.master” %>

In addition, an application can designate a default Master Page in web.config as shown here:

<configuration>
<system.web>
<pages masterPageFile="~/ MyMasterPage.master " />
</system.web>
</configuration>

(b)PreCompilation

By default, ASP.NET web pages and code files are compiled dynamically when a first request is made to the page. After the initial compilation, the compiled pages is cached; the cache is used to satisfy the subsequent requests for the same page. Even though this approach is flexible, when the page is requested for the first time, it requires a bit of extra time to compile the code. You can avoid this overhead by leveraging a new feature known as precompilation; by using this feature, you can compile an ASP.NET web site before making the web site available to the users.

(c)Sharing code in the application

In earlier version of ASP.NET, if you were to reference a reusable component from your dot net application, you had to compile the assembly and place it in the bin folder (or place it in the GAC) of the web application. But now with ASP.NET 2.0, creating a reusable component is very simple and straightforward. All you need to do is to create a component in a pre-defined subdirectory called code. Any component placed in this directory will be automatically compiled at runtime into a single assembly. This assembly is automatically referenced and will be available to all the page in the site.

(d)Themes and Skins

ASP.NET 2.0 introduces the concepts of Themes and Skins by means of which the look and feel of the web pages can be enhanced to a great extent to make them visually catchy and attractive.A skin is a set of visual attributes applied to a control type. A theme is a collection of skins. There are a lot of predefined themes in ASP.NET 2.0. One can use it by using the following line of code:

<%@ Page Theme=”SmokeAndGlass” %>

The page directive’s them attribute declaratively applies a theme to a page. Themes can also be applied programmatically using the page class’s Theme property

------------------------------------------------------------------------------------------------------------

Difference Between .net 2.o and .net 3.0?

.NET Framework 2.0

• A new hosting API for native applications wishing to host an instance of the .NET runtime
• Full 64-bit support for both the x64 and the IA64 hardware platforms.
• Language support for Generics built directly into the .NET CLR.
• Many additional and improved ASP.NET web controls.
• New data controls with declarative data binding.
• New personalization features for ASP.NET, such as support for themes, skins and webparts.

.NET Framework 3.0

• Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which will make use of 3D computer graphics hardware and Direct3D technologies.

• Windows Communication Foundation (WCF), formerly code-named Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.

• Windows Workflow Foundation (WWF) allows for building of task automation and integrated transactions using workflows.

• Windows CardSpace (WCS), formerly code-named InfoCard; a software component which securely stores a person's digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website.

Summary:

2.0 => framework that shipped with VS 2005 VB 8.0 / C# 2.0
3.0 => same framework as 2.0 + WCF + WPF + WF
3.5 => all the above + LINQ technologies and will ship with the next VS including VB 9.0 and C#

Sunday, April 26, 2009

Weigth Calculator

Hi Guys, want to know whether your body weight is normal or over just click on the link below you will come to know......

http://www.nhlbisupport.com/bmi/

Regards,
Vamshi

Friday, April 24, 2009

Hi

Hi..My Name is VamshiKrishna