C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




ASSEMBLY AND NAMESPACE


Posted Date: 07 May 2008    Resource Type: Articles    Category: .NET Framework

Posted By: devireddy       Member Level: Gold
Rating:     Points: 15



Difference between assembly n namespace

Namespace: It is a Collection of names wherein each name is Unique.
They form the logical boundary for a Group of classes.
Namespace must be specified in Project-Properties.

Assembly: It is an Output Unit. It is a unit of Deployment & a unit of versioning. Assemblies contain MSIL code.
Assemblies are Self-Describing. [e.g. metadata,manifest]
An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.
ADO.Net has some differences from ADO. The main differences are:
• ADO.Net is connectionless, rather than connection oriented. This means ALL datasets are disconnected. It does not mean you cannot keep a connection open, it just means that all the data you work with is a copy on the client side.
• ADO.Net can use XML
There are several important objects in ADO.Net we will briefly describe in the following table along with the most important properties or methods of those objects.
Objectt Purpose Important properties/methods
Connection To provide a connection to the data Properties:Connection String,data source, status,database
Methods: Open, Close, Dispose, ChangeDatabase, BeginTransaction,RollbackTransaction, CommittTransaction
The most important property of the connection object is the connection string. It provides the details of how to connect to a data source. Now here is an example of a connection string:
"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbserver;Data Source=mydatabase;"
What are those different items and what do they mean? Well Data Source, if its SQL Server, is the name of the actual server (if its Access its the complete path to the database mdb file). Initial Catalog is the actual database on the server (if the database is Access, then there is no initial catalog). If you use the Sqlconnection you don't have a provider, but if you use the OleDBConnection the provider parameter tells it which driver to use. Most people figure those out pretty easily. However the 'Integrated Security=SSPI' confuses many people. Basically if you choose to use integrated security your options are: Integrated Security=SSPI This is for trusted domains with SQL Server or Access
Integrated Security=yes This is ony for use with Oracle
MSDN Connection String Entry
MSDN ADO.Net Entry
btw if you want to know more about what SSPI (Security Support Interface) is click HERE

Adapter Populates the dataset with data and resolves changes from the dataset back to the data source Methods: Fill, dispose, update<
Dataset can read databases or XML files. Similar to a recordset with CursorLocation = adUseClient, CursorType = asOpenStatus, LockType = adLockOptimistic
DataReader like an ado recordset with cursortype = adOpenForwardOnly and LockType = adLockReadOnly Properties: IsClosed,FieldCount
Methods: Close, GetBoolean, GetChars, GetByte, etc., Read, NextResult
Command Purpose Properties: CommandText,CommandTimeout default 30, CommandType (StoredProcedure, TableDirect, Text),Connection,Parameters
Methods: Cancel,CreateParameter,Dispose,ExecuteNonQuery,ExecuteReader,ExecuteScaler, ExecuteXML Reader


Data-releated namespaces
Namespace Purpose
System.Data This is the core ADO.net namespace
System.Data.Common Basic utility classes that are inherited by .Net providers
System.Data.SqlClient .Net SQL Server components
System.Data.Oledb .Net Generic components
System.Xml Classes and interfaces needed to support XML processing

Important Data Related Exceptions
• System.Data.DataException
• System.Data.RowNotInTableException
• System.Data.NoNullAllowedException
• System.Data.MissingPrimaryKeyException
• System.Data.InvalidExpressionException
• System.Data.SyntaxExpressionException
• System.Data.ConstraintException
• System.data.SQLClient.SQLClientException
• System.data.OleDBClient.OleDBClientException


Code Sample
Basic code to connect to an sql database ,fill textboxes, move forward and back, add, and save, is given here:
Public Class Form1

Inherits System.Windows.Forms.Form
Dim objcon As SqlConnection = New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LPL_Rating;Data Source=dfwapp01;")
Dim myadapter As SqlDataAdapter = New SqlDataAdapter("Select top 100* From TblQuotes1", objcon)
Dim mydataset As New DataSet()
Dim currow As Integer

#Region " Windows Form Designer generated code "


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objcon.Open()
myadapter.Fill(mydataset, "Select top 100* From TblQuotes1")
currow = 0
fill_textboxes(currow)
End Sub

Private Sub fill_textboxes(ByVal irow As Integer)
Try
TextBox1.Text() = mydataset.Tables(0).Rows(irow).ItemArray.GetValue(0).ToString
TextBox2.Text() = mydataset.Tables(0).Rows(irow).ItemArray.GetValue(1).ToString
TextBox3.Text() = mydataset.Tables(0).Rows(irow).ItemArray.GetValue(2).ToString
Catch e As Exception
MsgBox(e.ToString)

End Try
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
currow += 1 fill_textboxes(currow)
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
currow -= 1
fill_textboxes(currow)
End Sub

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim newrow As DataRow = mydataset.Tables(0).NewRow

Dim icount As Integer

newrow(0) = TextBox1.Text
newrow(1) = TextBox2.Text
newrow(2) = TextBox3.Text

mydataset.Tables(0).Rows.Add(newrow)
myadapter.Update(mydataset, "tblquotes1")

End Sub
Adapter acts as a bridge between your data source and the dataset/datatable. The main advantage is it has all the data manipulation commands(select,insert,update,delete) and is highly sophisticated. but not needed all the time for us. Note, if you configure the adapter well in advance during design time, visual studio creates a connection also.

On the otherhands, a command object can be created runtime for a sql statement and works for an existing connection.

Adapter may be thought of an agent who could get/update data for us. It works in sync. with other data objects like dataset, datatable.

Command object is specifically designed for issuing a sql statement (including stored proc).



Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.

Ø A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change.
Ø The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.
Ø An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.





Responses

Author: Sebastian    13 Jun 2008Member Level: Gold   Points : 1
This is very informative. Thanks for sharing the details.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Some key concepts in the dotnet
Previous Resource: DATASET VS DATAREADER
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use