Thursday, March 27, 2008

Dot Net and java Battle Continues


Even if you don't write code dedicated to Microsoft platforms, you have
probably heard by now about Microsoft .NET, Microsoft's latest volley in
their campaign against all things non-Windows. If you've read the media
spin from Microsoft, or browsed through the scant technical material
available on the MSDN site, or even if you attended the Microsoft
Professional Developers' Conference (where the .NET platform was officially
"launched"), you're probably still left with at least two big questions:





  • What exactly is the .NET platform?
  • How does the .NET architecture measure up against J2EE?



And, if you think more long-term, you might have a third question rattling
around your head:


  • What can we learn from the .NET architecture about pushing the
    envelope of enterprise software development?



The .NET framework is at a very early stage in its lifecycle, and deep
details are still being eked out by the Microsoft .NET team. But we can,
nevertheless, get fairly decent answers to these questions from the
information that's already out there.



What is it?



Current ruminations about .NET in various forums are reminiscent of the
fable of the three blind men attempting to identify an elephant: It's
perceived as very different things, depending on your perspective. Some
see .NET as Microsoft's next-generation Visual Studio development
environment. Some see it as yet another new programming language (C#).
Some see it as a new data-exchange and messaging framework, based on
XML and SOAP. In reality, .NET wants to be all of these things, and a bit
more.


First, let's get some concrete details. Here's one cut at an itemized list of
the technical components making up the .NET platform:



  • C#, a "new" language for writing classes and components, that
    integrates elements of C, C++, and Java, and adds additional
    features, like metadata tags, related to component development.


  • A "common language runtime", which runs bytecodes in an
    Internal Language (IL) format. Code and objects written in one
    language can, ostensibly, be compiled into the IL runtime, once an IL
    compiler is developed for the language.


  • A set of base components, accessible from the common language
    runtime, that provide various functions (networking, containers,
    etc.).



  • ASP+, a new version of ASP that supports compilation of ASPs into
    the common language runtime (and therefore writing ASP scripts
    using any language with an IL binding).


  • Win Forms and Web Forms, new UI component frameworks accessible from
    Visual Studio.


  • ADO+, a new generation of ADO data access components that use XML and
    SOAP for
    data interchange.


How do .NET and J2EE compare?



As you can see, the .NET platform has an array of technologies under its
umbrella. Microsoft is ostensibly presenting these as alternatives to other
existing platforms, like J2EE and CORBA, in order to attract developers to
the Windows platform. But how do the comparisons play out item-by-item?
One way to lay out the alternatives between .NET and J2EE is shown in the
following table:




































color="#FFFFFF">Microsoft.NET J2EE Key differentiators
C# programming language Java programming language C# and Java both derive from C and C++. Most
significant
features (e.g., garbage collection, hierarchical namespaces) are present in
both. C# borrows some of the component concepts from JavaBeans
(properties/attributes, events, etc.), adds some of its own (like metadata
tags), but incorporates these features into the syntax differently.



Java runs on any platform with a Java VM. C# only runs in Windows for the
foreseeable future.


C# is implicitly tied into the IL common language runtime (see below), and
is run as just-in-time (JIT) compiled bytecodes or compiled entirely into
native code. Java code runs as Java Virtual Machine (VT) bytecodes that are
either interpreted in the VM or JIT compiled, or can be compiled entirely
into native code.

.NET common components (aka the ".NET
Framework SDK")
Java core API High-level .NET components will include support for
distributed access using XML and SOAP (see ADO+ below).
Active Server Pages+
(ASP+)
Java ServerPages (JSP) ASP+ will use Visual Basic, C#, and possibly other
languages for code snippets. All get compiled into native code through the
common language runtime (as opposed to being interpreted each time, like
ASPs). JSPs use Java code (snippets, or JavaBean references), compiled into
Java bytecodes (either on-demand or batch-compiled, depending on the JSP
implementation).
IL Common Language
Runtime
Java Virtual Machine and CORBA IDL and ORB .NET common language runtime allows code in multiple
languages to use a shared set of components, on Windows. Underlies nearly
all of .NET framework (common components, ASP+, etc.).

Java's Virtual Machine spec allows Java bytecodes to run on any platform
with a compliant JVM.

CORBA allows code in multiple languages to use a shared set of objects,
on any platform with an ORB available. Not nearly as tightly integrated into
J2EE framework.

Win Forms and Web Forms Java Swing Similar web components (e.g., based on JSP) not
available in Java standard platform, some proprietary components available
through Java IDEs, etc.

Win Forms and Web Forms RAD development supported through the MS
Visual Studio IDE - no other IDE support announced at this writing. Swing
support available in many Java IDEs and tools.

ADO+ and SOAP-based Web
Services
JDBC, EJB, JMS and Java XML Libraries (XML4J,
JAXP)
ADO+ is built on the premise of XML data interchange
(between remote data objects and layers of multi-tier apps) on top of HTTP
(AKA, SOAP). .NET's web services in general assume SOAP messaging models.
EJB, JDBC, etc. leave the data interchange protocol at the developer's
discretion, and operate on top of either HTTP, RMI/JRMP or IIOP.



The comparisons in this table only scratch the surface. Here's an executive
summary of .NET vs. J2EE:


Features: .NET and J2EE offer pretty much the same laundry of list of features,
albeit in different ways.


Portability: The .NET core works on Windows only but theoretically
supports development in many languages (once sub-/supersets of these
languages have been defined and IL compilers have been created for them).
Also, Net's SOAP capabilities will allow components on other platforms to
exchange data messages with .NET components. While a few of the
elements in .NET, such as SOAP and its discovery and lookup protocols, are
provided as public specifications, the core components of the framework (IL
runtime environment, ASP+ internals, Win Forms and Web Forms
component "contracts", etc.) are kept by Microsoft, and Microsoft will be the
only provider of complete .NET development and runtime environments.
There has already been some pressure by the development community for
Microsoft to open up these specifications, but this would be counter to
Microsoft's standard practices.




Read more on the .NET platform in this in-depth interview by
O'Reilly Windows editor John Osborn:



Deep Inside C#: An Interview with Microsoft chief architect
Anders Hejlsberg
--John gets to the bottom of not only Microsoft's
detailed plans for the C# programming language but also the .Net
framework.







J2EE, on the other hand, works on any platform with a compliant Java VM
and a compliant set of required platform services (EJB container, JMS
service, etc., etc.). All of the specifications that define the J2EE platform
are published and reviewed publicly, and numerous vendors offer compliant
products and development environments. But J2EE is a single-language
platform. Calls from/to objects in other languages are possible through
CORBA, but CORBA support is not a ubiquitous part of the platform.

The Bigger Picture



These last points highlight some of the key differentiators between .NET
and J2EE, and point towards Microsoft's real play here. Microsoft is doing two
very notable things with .NET: It is opening up a channel to developers in
other programming languages, and it is opening up a channel to non-.NET
components by integrating XML and SOAP into their messaging scheme.


By allowing cross-language component interactions, .NET is enfranchising
Perl, Eiffel, Cobol, and other programmers by allowing them to play in the
Microsoft sandbox. Devotees of these languages are particularly amenable to
gestures like this, since for the most part they have felt somewhat
disenfranchised and marginalized in the Microsoft/Sun/Open Source wars. And
by using XML and SOAP in their component messaging layer, Microsoft is
bolstering their diplomatic face and adding an element of openness to their
platform, providing ammunition against claims of proprietary behavior.

What's the correct response?



For Microsoft developers:


.NET is a good thing for those of you committed to Microsoft architectures.
ASP+ is better than ASP, ADO+ is better, but different, than ADO and
DCOM, C# is better than C and C++. The initial version of .NET won't be
real until sometime in 2001, so you have some time to prepare, but this will
undoubtedly become the default development environment for Microsoft
platforms. And if you're developing within the Microsoft development
framework now, you will undoubtedly benefit from adopting elements of the
.NET framework into your architectures.



However, several of the goals of the .NET platform are fairly lofty and not at
all guaranteed to fly, at least not in the short term. The IL common
language runtime, for example, has some fairly significant hurdles to
overcome before it has any real payoff for developers. Each language that
wants to integrate with the component runtime has to define a
subset/superset of the language that maps cleanly into and out of the IL
runtime, and has to define constructs that provide the component metadata that
IL requires. Then compilers (x-to-IL and IL-to-x) will have to be developed
to both compile language structures (objects, components, etc.) into IL
component bytecodes, and also generate language-specific interfaces to
existing IL components.


There is some historical precedence here. Numerous bridges from non-Java
languages to the Java VM have been developed, such as
JPython,

PERCobol
,
the Tcl/Java
project
, and interestingly enough,

Bertrand Meyer
and some other Eiffel folks put together an
target="new">Eiffel-to-JavaVM system a few years back.
With the possible exception of JPython, these tools have not been widely
adopted, even within their respective language communities, even though
they seem to offer a way to write code for the Java environment (albeit not
the entire J2EE framework) using your favorite language. Why this lack of
enthusiasm? I believe it's because people are hesitant to take on the
headaches of adding yet another translation step from their development
language to the target framework. If the Java environment is the goal, people
will generally choose to learn Java. I predict that the same will be true of
.NET: People will generally choose to learn C# and write .NET components in
that language.



Another caution: Beware of performance issues with .NET's SOAP-based
distributed communications. SOAP essentially means XML over HTTP. HTTP
is not a high-performance data protocol, and XML implies an XML parsing
layer, which implies more compute overhead. The combination of both
could significantly reduce transaction rates relative to alternative
messaging/communications channels. XML is a very rich, robust
metalanguage for messaging, and HTTP is very portable and avoids many
firewall issues. But if transaction rates are a priority for you, keep your
options open.


For the Java and Open Source communities:


It would be easy to dismiss .NET as more Microsoft marketing-ware and
continue on your merry way. But don't. .NET is a sign of a subtle but
significant shift in Microsoft's strategy to evangelize their platforms. They
have been fighting alternative frameworks and platforms at the
management level pretty well, touting the usual questionable "statistics"
about cost of ownership and seamless integration. Now they are fighting
Java and open source initiatives on their own terms, putting their own spin
on "open" and attempting to directly address the needs of developers, two
things that they have been faulted for not doing very well in the past. If you
consider yourself an evangelist for Java or open source platforms, then the
nature of the war is changing. Be prepared.


Also, Microsoft's IL runtime has at least one notable, if improbable, goal:
eliminate the programming language as a barrier to entry to the framework.
Java eliminates the platform barrier (within limits, of course: You can't
make up for missing hardware resources with software, for example), but in
order to work in J2EE, you have to work in Java. .NET wants to let you use
the language of your choice to build .NET applications. This is admirable,
though there are big questions as to whether and when the IL approach in
.NET will actually become broadly useful (see above). Regardless, this
points to a weakness in the single-language J2EE approach. The importance
of this weakness is questionable, but it exists nonetheless, and deserves
some consideration by the Java community. If this is really desired by
developers, then maybe the efforts in Java bytecode generators for non-
Java languages should be organized and consolidated.


Focusing on J2EE, there are a few issues that should be addressed
immediately in order to bolster the advantages of that platform compared
to what .NET is shooting for. First, XML support needs to be integrated
seamlessly into the framework. I'm not talking about bolting an XML
SAX/DOM parser to the set of standard services, or extending the use of
XML in configuration files. XML messaging and manipulation need to be
there, ready to use. Admittedly, you can use XML payloads on top of JMS
messaging, but the platform doesn't facilitate this at all. The XML space is a
cluttered mess of standards, de facto standards, APIs and DTDs, which is to
be expected when you're dealing with a meta-language.


But Microsoft has put a stake in the ground with SOAP, and they're pushing hard
to put something understandable and useful in the hands of developers. J2EE
proponents need to do the same with their platform. One possibility that
comes to mind is to add an XML messaging "provider" layer on top of JMS,
along the lines of the pattern followed by
Java Naming and
Directory Interface
, or JNDI, with LDAP, NIS, COS Naming, etc. This in
combination with a standard SOAP/BizTalk provider, an ebXML provider, etc.
would be an impressive statement.



Clarifications and Corrections



Since the publication of this article in August 2000,
40 readers have responded with their own thoughts about
.Net vs. J2EE. Jim Farley,
the author of this article, has sifted through those comments, as
well as email he's received, and added the following clarifications and
corrections.

Clarifications



The description of C#'s compilation features vs. those of Java seems to have
confused some readers. To put it another way: C# code always runs natively.
Java code typically runs as interpreted bytecodes, and can run natively. C#
is either compiled entirely to native code, or it is compiled into the common
language runtime bytecodes and then just-in-time compiled to native code
during execution. Java code, on the other hand, typically runs as
runtime-interpreted bytecodes (from which its cross-platform abilities
spring), and can also run in a just-in-time compiled context. Some Java
native-code compilers also exist (Jove, BulletTrain, JET, etc.).


As a side note, Microsoft claims that the default interpretive mode of Java
is a liability, in that bytecodes designed for a virtual machine do not lend
themselves as well to native optimization. I haven't seen any hard data to
prove or disprove that claim, either generally (bytecodes vs. native-compiled
languages) or specifically (Java vs. C#).


Several readers, in response to the
call to include XML support in J2EE, mentioned the fact that J2EE 1.3
(currently in public draft) requires that any J2EE-compliant product must
include Java XML SAX and DOM parsers. But this is just "bolting an XML
SAX/DOM parser" to J2EE, as I mentioned. I was calling for it to be taken a
step farther, to incorporate XML support directly in the J2EE support APIs.
Ideally, J2EE-based components and services would have XML support (for
messaging, interface description exports, etc.) automatically built-in, to
some extent.



Corrections



I state in the article that C# "borrows some of the component concepts
from JavaBeans." This statement can't be proven, and, as several readers
pointed out, it's more likely that Microsoft based the component functionality
of C# more on their own COM and VB models, with influences from other
pre-existing component models.



Jim Farley
is a technology architect, strategist and IT manager.

















Guitar tabs of our National Anthem

Jana Gana Mana - National Anthem Guitar Tabs

Try it... Very beutifully composed.........


Jana Gana Mana

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

E|--------0--0--0--0--0--0-0-0-0-----0--1------------|
B|--1--3---------------------------3-----------------|
c d e e e e e e e e e d e f
Jana gana mana adhinayaka, jaya he


E|---0--0--0-----------------------------------------|
B|-------------3---3---3-0-3-1-----------------------|
e e e d d d b d c
Bharata bhagya vidhata

E|-------3-3---3---3----3-3-3-3----3-3/5-1----------|
B|---1-1---------------------------------------------|
c c g g g g g g g g g g/a f
Punjab Sindhu Gujarata Maratha

E|---1-1-1-----1-1-0---------1-0---------------------|
B|-------------------3-----3-------------------------|
f f f f f e d d f e
Dravida Utkala Banga

E|----0----0------0-0-------0-3-3-5---1-1------------|
B|--------------3-----3------------------------------|
e e d e e d e g g a f f
Vindhya Himachala Yamuna Ganga

E|---0--0--0----0--0---------------------------------|
B|--------------------3----3-0-3-1-------------------|
e e e e e d d b d c
Uchchala Jaladhi taranga

E|---------0--0-----0-0------1-----------------------|
B|--1-3--------------------3-------------------------|
c d e e e e d f
Tava shubha name jage

E|--0-1---3--3----3-1-0------1-0---------------------|
B|-------------------------3-------------------------|
e f g g g f e d f e
Tava shubha ashish maange

E|--1-0--0-0-----------------------------------------|
B|-------------3-3---0-3-1---------------------------|
f e e e d d b d c
Gahe tava jaya gatha

E|--------3--3--3--3-------3-3--3-3-3--5-------------|
B|--1-1------------------5---------------------------|
c c g g g g e g g g g g a
Jana gana mangala dayaka jaya he

E|---1-1-1----1-1-----0---1-0------------------------|
B|----------------------3----------------------------|
f f f f f e d f e
Bharata bhagya vidhata

E|---------8---7-5--7----5-3-5-----------------------|
B|----5-8--------------------------------------------|
e g c b a b a g a
Jaya he, jaya he, jaya he

E|----------------0-0------0-1-----------------------|
B|------1-1--3-3---------3---------------------------|
c c d d e e d e f
Jaya jaya jaya, jaya he

Saturday, February 23, 2008

URL REDIRECTION MADE POSSIBLE ......

Hai Friends , Some of you me be wondered, why when i am clicking on a website like www.sreejiths.co.nr , i came atlast in to a blog.... Your doubt is good.

This process is very much called URL REDIRECTION. Its not a recent phenomenon... so i am not supposed to tell much more about it... Last 4 months.. i trying to register a webiste by my name... I done some research and found out that, it is 2 step process..
First you have to register a domain for example. co domain, or .com, or .co.in.... , .NET like that.....
Second you have to borrow some space from ISP providers to host your domain.....

First one cost you around.. 400 -800 nearly....
Second one cost you around 2000-10,000 depending upon, cost of maintainance, Kind of Webserver you are hosting and which os they are supporting and finally which languages editing they are supporting, theat is back end support,..............

so i leave off temperarly my wish........

Actaully the website you are in now is a blog....... its actall url is www.sreejithcools.blogspot.com.
i want to remove this lengthy url. Finally i came to know about the url redirection thechnique.... which most websites are now giving.... freely......

i made it possible with www.freedomains.co.nr.......


try it out urself........................
good luck and happy bloging....


Tuesday, February 19, 2008

HOW TO CONNECT WITH 2 LAPTOPS WIRELESSLY.

With two laptops with the same version of Windows and wireless adapters, you can share information, chat or play game wirelessly.

Most of the laptops have Wi-fi or wireless connection. Therefore, you do not need any wire to connect two laptops in your house or in your office. All you need to do is to create a pear-to-pear connection between these two.

At first, you have to label IP for laptops you want to connect because they normally do not have an access point. Here's how you create an IP for your laptop:

Step 1: Open "Wireless Network Connection Status" (Image 1) in your Windows (it should locate in your system tray". If not, you can still open it in control panel).

Step 2: Click "Properties" to open "Wireless Network Connection Properties" (Image 2).

Step 3: Double-click "Internet Protocol (TCP/IP)" and set IP for both of your laptops. The IP address can be random. However, you should have the same "Subnet mask". For example:

Computer 1:

IP: 10.0.0.32

Subnet mask: 311.311.311.0

Computer 2:

IP: 10.0.0.33

Subnet mask: 311.311.311.0

You can leave other information blank.

Now, after having their own IP, your laptops can be connected to each other. You have to go to the taskbar and find "Wireless Network Connection" symbol. Right-click and choose "Change the order of preferred networks" in the appeared window.

Next, you have to add a new network. Name your network at "Network name" blank and create a password at "Network key". Notice that you have to mark "This is a computer to computer".

Find the symbol of wireless network in system tray right-click to it. Choose "View wireless network". Click "Connect". Now, one of your computers will broadcast signal and with for other computer to connect. In the computer that receives signal, search for the network that you created and named. Click "Connect".

After connecting two laptops, you can share files, chat or even play game through LAN. Using "Net meetings" (available in most version of Windows) would be the best way to use the connection. Go to run, type in Conf to open Net Meeting.

Monday, February 18, 2008

MY LAP OR ACER ASPIRE 4315







Configuration

Intel® Celeron® M Processor 530SR

(1.73GHz, 1MB Cache, 533MHz FSB)

Mobile Intel® GL960 Express chipset with integrated 3D graphics,

GMA X3100, up to 358 MB of Intel DVMT 4.0

(8 MB of dedicated, up to 350 MB of shared system memory),

Supporting Microsoft® DirectX® 9.0

14.1" Wide XGA CrystalBrite (200 nit) Color LCD

80GB SATA HDD, 512MB DDR2 RAM (upgradeable to 2GB)

Integrated 56Kbps modem & 10/100 Mbps LAN

Integrated 802.11b/g Wireless LAN

Integrated DVD/CD-RW combo drive

Two built-in Acer 3DSonic stereo speakers

6-cell Li-Ion Battery Pack (2.0 hours battery life)

(Actual battery life may vary, depending on usage and configuration).

3xUSB, 1xVGA port, ExpressCard/54 slot, S-video/TV-out (NTSC/PAL) port

344 (W) × 246 (D) × 37/42 (H) mm, Weight 2.6kg

1-Year International Traveller Warranty
Acer Designed Carrying Bag

Sunday, February 17, 2008

WHY SHOULD I USE PUBLIC STATIC VOID MAIN( STRING [] WHATEVER) ??

Consider the following Code ….
-----------------------------------------------

Public static void main (String args[])
public class a {
void doit() { // whatever you want here
}
public static void main(String args[]) {
a w = new a();
w.doit();
}
}
-------------------------
public: This method needs to be accessed outside the class

static: You need not have an instance to access the method.
java Foo

would get converted to Foo.main().

void: Your application need not return a value, as the JVM launcher would return the value when it exits. If you need to return a value, use System.exit();

main(): This is the entry point for the application...

String args[] : You can pass arguments to your application
------------------------------------
The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.
In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started.

The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value. As you will see, methods may also return values.
As stated, main( ) is the method called when a Java application begins. Keep in mind that Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.
Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If there are no parameters required for a given method, you still need to include the empty parentheses. In main( ), there is only one parameter, albeit a complicated one. String args[ ] declares a parameter named args, which is an array of instances of the class String. Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.

Friday, February 15, 2008

Data base access in C# and Java. Feel the difference

Database Access (C# vs Java)

C# and Java use similar means for accessing database data. Both C# and Java require a database driver to perform the actual database operations. In addition, both require a database connection, a SQL query to execute against the database connection, and a result set from the execution of the query.

Comparing Database Drivers

Database drivers such as JDBC or ODBC can be used to access data in Java and C#. The Java Database Connectivity (JDBC) driver is used from a program written in Java. Open Database Connectivity (ODBC) is Microsoft's database programming interface for accessing a variety of relational databases on a number of platforms. There is also a JDBC-ODBC bridge standard on both the Solaris and Windows versions of the Java platform so you can also use ODBC from a Java program.

In Java, the connection string information is supplied to the driver for a connection handle, as follows:

Java

final static private String url = "jdbc:oracle:server,user,pass, …)";


In C#, using the .NET Framework, you do not have to load ODBC or JDBC drivers in order to access the database. Simply set the connection string for the database connection object, as follows:

C#

static string connectionString = "Initial Catalog=northwind;Data Source=(local);Integrated Security=SSPI;";
static SqlConnection cn = new SqlConnection(connectionString);



Java Read Database Example

In Java, to perform a database read operation, you can use a ResultSet object created by the executeQuery method of the Statement object. The ResultSet object contains the data returned by the query. You can then iterate through the ResultSet object to access the data.

The following example provides the Java code to read from a database.



Connection c;
try
{
Class.forName (_driver);
c = DriverManager.getConnection(url, user, pass);
}
catch (Exception e)
{
// Handle exceptions for DriverManager
// and Connection creation:
}
try
{
Statement stmt = c.createStatement();
ResultSet results = stmt.executeQuery(
"SELECT TEXT FROM dba ");
while(results.next())
{
String s = results.getString("ColumnName");
// Display each ColumnName value in the ResultSet:
}
stmt.close();
}
catch(java.sql.SQLException e)
{
// Handle exceptions for executeQuery and getString:
}


Similarly, to perform a database write operation, a Statement object is created from the Connection object. The Statement object has methods for executing SQL queries and updates against a database. Updates and queries are in the form of a string containing the SQL command of a write operation used in the executeUpdate method of the Statement object to return a ResultSet object.

C# Read Database Example

In C#, using the .NET Framework, accessing data is further simplified through the set of classes provided by ADO.NET, which supports database access using ODBC drivers as well as through OLE DB providers. C# applications can interact with SQL databases for reading, writing, and searching data using.NET Framework's ADO.NET classes, and through a Microsoft Data Access Component (MDAC). The .NET Framework's System.Data.SqlClient namespace and classes make accessing SQL server databases easier.

In C#, to perform a database read operation, you can use a connection, a command, and a data table. For example, to connect to a SQL Server database using the System.Data.SqlClient namespace, you can use the following:

A SqlConnection class.

A query such as a SqlCommand class.

A result set such as a DataTable class.

The .NET Framework provides the DataAdapter, which brings these three objects together, as follows:

The SqlConnection object is set using the DataAdapter object's connection property.

The query to execute is specified using the DataAdapter's SelectCommand property.

The DataTable object is created using the Fill method of the DataAdapter object. The DataTable object contains the result set data returned by the query. You can iterate through the DataTable object to access the data rows using rows collection.

To compile and run the code, you need the following; otherwise, the line databaseConnection.Open(); fails and throws an exception.

Microsoft Data Access Components (MDAC) version 2.7 or later.

If you are using Microsoft Windows XP or Windows Server 2003, you already have MDAC 2.7. However, if you are using Microsoft Windows 2000, you may need to upgrade the MDAC already installed on your computer. For more information, see MDAC Installation.

Access to the SQL Server Northwind database and integrated security privileges for the current user name running the code on a local SQL Server with the Northwind sample database installed.

C#
// Sample C# code accessing a sample database

// You need:
// A database connection
// A command to execute
// A data adapter that understands SQL databases
// A table to hold the result set

namespace DataAccess
{
using System.Data;
using System.Data.SqlClient;

class DataAccess
{
//This is your database connection:
static string connectionString = "Initial Catalog=northwind;Data Source=(local);Integrated Security=SSPI;";
static SqlConnection cn = new SqlConnection(connectionString);

// This is your command to execute:
static string sCommand = "SELECT TOP 10 Lastname FROM Employees ORDER BY EmployeeID";

// This is your data adapter that understands SQL databases:
static SqlDataAdapter da = new SqlDataAdapter(sCommand, cn);

// This is your table to hold the result set:
static DataTable dataTable = new DataTable();

static void Main()
{
try
{
cn.Open();

// Fill the data table with select statement's query results:
int recordsAffected = da.Fill(dataTable);

if (recordsAffected > 0)
{
foreach (DataRow dr in dataTable.Rows)
{
System.Console.WriteLine(dr[0]);
}
}
}
catch (SqlException e)
{
string msg = "";
for (int i=0; i < e.Errors.Count; i++)
{
msg += "Error #" + i + " Message: " + e.Errors[i].Message + "\n";
}
System.Console.WriteLine(msg);
}
finally
{
if (cn.State != ConnectionState.Closed)
{
cn.Close();
}
}
}
}
}

 
Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes