For how long will you try to search and waste your time to found information.How time did you waste searching for these snippets and customizing them for your need ?You and many programers are every day wasting time serfing the web for code in sites, blogs, forums... Asking and waiting for a reply...Now you have to change ! A new idea come to my mind... A simple namespace, very simple, quite simple that will solve the whole problem.And how does this do the work ?You want grantue that you'll find what you are searching for, but the class will be easy to manipulate.How this works ?Simply add the "DLL" to your reference in your project then use imports to import it !And how much it helps ?Here the adventure start, the small DLL will contain many many classes in various categories.For example you can compress, resize, rotate, mirror a picture in the imaging class.Or encrypt decrypt string, generate passwords.. in the Data ClassAnd many many more.Developer : Omar Abid (only me, the starting is always hard)Time : About 1 YearEstimated numbers of line : About 20.000 line

Now imagine about 20.000 that becomes only 1!Yes when it finishs you don't have to ;)

Thinking of it ? Why Dot Net or My don't provide th ease of knowing the folder size ?k Bro you have to do it ur self, but if you didn't this is the code 4 u

Public abort As Boolean Function GetFolderSize(ByVal DirPath As String, ByVal includeSubFolders As Boolean) As Long Try Dim size As Long = 0 Dim diBase As New DirectoryInfo(DirPath) Dim files() As FileInfo If includeSubFolders Then files = diBase.GetFiles("*", SearchOption.AllDirectories)

You read the old sample of shutting down Windows ??Sure it works but I tried it with Vista and it doesn't !!Bref, we don't have permissionSo I made a search again, and let's fight to get this permission !

The Windows ClassUse the following to Shut, Reboot and logoffWindows.ExitViaShutdown()Windows.ExitViaReboot( )Windows.ExitViaLogoff( )

' ----- Close all the streams.sourceStream.Close( )compressedStream.Close( )destinationStream.Close( )End Sub

Public Sub FileDecompress(ByVal sourceFile As String, _ByVal destinationFile As String)' ----- Compress the entire contents of a file, and' store it in a new file. First, get the files' as streams.Dim sourceStream As New FileStream( _sourceFile, FileMode.Open, FileAccess.Read)Dim destinationStream As New FileStream( _destinationFile, FileMode.Create, FileAccess.Write)

Class EncryptionPublic Function GetHash(ByVal plainText As String) As String' ----- Generate a hash. Return an empty string' if there are any problems.Dim plainBytes As Byte()Dim hashEngine As MD5CryptoServiceProviderDim hashBytes As Byte()Dim hashText As String

Public Function StringEncrypt(ByVal plainText As String, _ByVal keyText As String) As String' ----- Encrypt some text. Return an empty string' if there are any problems.Try' ----- Remove any possible null characters.Dim workText As String = plainText.Replace(vbNullChar, "")

Public Function StringDecrypt(ByVal encrypted As String, _ByVal keyText As String) As String' ----- Decrypt a previously encrypted string. The key' must match the one used to encrypt the string.' Return an empty string on error.Try' ----- Convert encrypted string to a byte array.Dim workBytes() As Byte = _Convert.FromBase64String(encrypted)

Hi!If you are making the chat (TCP/IP) program, just I tape the strating on the previous I found this step helpful for you so that your user can determine the Name of the IP Address that they are sending to !Vice versa, the IP address of the host ;)This is the code :First imports "System.Net.Dns"Now learn how to get the IP address of the Local Computer !Dim hostAddresses() As Net.IPAddressDim ipList As String = ""Dim Address As Net.IPAddress

hostAddresses = Net.Dns.GetHostAddresses(Net.Dns.GetHostName())For Each Address In hostAddressesipList &= vbCrLf & Address.ToString()Next AddressMsgBox(Net.Dns.GetHostName() & vbNewLine & ipList)and then get the host name of an ip :MsgBox(Net.Dns.GetHostEntry("127.0.0.1").HostName)or Resolve the IP address of a hostDim hostEntry As Net.IPHostEntryDim scanAddress As Net.IPAddressDim hostAddresses As String = ""hostEntry = Net.Dns.GetHostEntry("vectra")For Each scanAddress In hostEntry.AddressListMsgBox(scanAddress.ToString())Next scanAddress

Hi again,Did you though before of a chat over TCP/IP (Local Network).If you decided to make a project of this chat, so let me help you begin (just the basics an then you can do all)What you need is to know how, you can make it easily with the Net command!the command "Net Send ComputerName(or IP address) message"It accept IP Address, so even on an Internet Network !!You have the command so you can make it !This the code (if you don't know how to code)dim Message as string = "Hello"dim TragetComputer as string = "192.168.2.1"Process.Start("net.exe", _"send " & TargetComputer & _" """ & Message & """")

But thar doesn't send !!So you have to check the Messenger Service !Click Start Control Panel, and open the Administrative Tools panel.Within the Administrative Tools panel, open Services.Locate Messenger, and double-click its icon to open the Messenger Properties window.Set the Startup Type to Automatic, and click the Start button.Click the OK button, and close all open Control Panel windows.

Automatics will make it run every time the windows open !have a good time :)

I know that all can send mails because it's easy, lol ! but when thinking about how to receive them!So see and try !Well we'll use here the TCPClient Class in the System.net.socketThe following class code creates Pop3 objects to simplify accessing emails from a standard POP3 server.But keep in mind that some servers require SSL or other authentication.First create the class "POP3" and put this code on it :

Public Class Pop3' ----- The default TCP/IP port number for POP3 is 110.Public Port As Integer = 110Public Messages As Integer = 0

Private Const CommandFailure As String = "-ERR"

Private Pop3Server As TcpClientPrivate CommandSender As NetworkStreamPrivate ContentReceiver As StreamReader

Public Sub Connect(ByVal serverName As String, _ByVal userName As String, ByVal password As String)' ----- Initiate the connection to a POP3 server.Dim commandData As StringDim contentBuffer() As ByteDim responseString As StringDim parts() As String

' ----- End the connection.ContentReceiver.Close()CommandSender.Close()

Pop3Server.Close()End Sub

Function GetMessage(ByVal whichMessage As Integer) _As String' ----- Retrieve a single email message.Dim commandData As StringDim contentBuffer() As ByteDim responseString As StringDim theMessage As New System.Text.StringBuilderDim oneLine As String

' ----- Check for an invalid message.If (whichMessage <> Messages) ThenThrow New ArgumentOutOfRangeException(whichMessage, _"Messages are numbered from 1 to the number " & _"identified by the Messages property.")End If

Now let's Manage the form (make a new form) so add three TextBox controls named ServerName, UserName, and UserPassword. Set the UserPassword control's PasswordChar field to the asterisk character (*). Add a ListBox control named MessageList and two Button controls named ActGet and ActView. Set the Button controls' Text properties to Get Messages and View Message, respectively.

A simple sample but very helpful when you want to know active windows and process around you !

Dim Proc() As Process = Process.GetProcesses For Each p As Process In Proc Me.ListBox1.Items.Add("Process Name - " & p.ProcessName) Next For Each p2 As Process In Proc If p2.MainWindowTitle <> "" Then Me.ListBox1.Items.Add("Process window title - " & p2.MainWindowTitle) End If Next

Yeah,This is the first part of my Print Tutorial ! OK will help you begin =)

In this small tutor I 'll show you some basics of printing with VB 2005, I made and tested my self.Ok may be the first thing to think on is to find printers on the computer.So take a look @ this codeOk add a new combo box and all should works well !Dim InstalledPrinters As String' Find all printers installedFor Each InstalledPrinters In _PrinterSettings.InstalledPrinterscombobox1.Items.Add(InstalledPrinters)Next InstalledPrinters' Set the combo to the first printer in the listIf combobox1.Items.Count > 0 Thencombobox1.SelectedIndex = 0End IfNow let's learn some basics of preview and print. So let's think on how to preview a document.First let's make a design to our preview (some limits) we need then to use VB PenTake a look, the following code will help you to show a pageview !This is the whole code to more help you !Public Class Form1Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "Public Sub New()MyBase.New()'This call is required by the Windows Form Designer.InitializeComponent()'Add any initialization after the InitializeComponent() callEnd Sub'Form overrides dispose to clean up the component list.Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)If disposing ThenIf Not (components Is Nothing) Thencomponents.Dispose()End IfEnd IfMyBase.Dispose(disposing)End Sub'Required by the Windows Form DesignerPrivate components As System.ComponentModel.IContainer'NOTE: The following procedure is required by the Windows Form Designer'It can be modified using the Windows Form Designer.'Do not modify it using the code editor.Friend WithEvents btnPreview As System.Windows.Forms.ButtonFriend WithEvents pdocTest As System.Drawing.Printing.PrintDocumentFriend WithEvents ppdTest As System.Windows.Forms.PrintPreviewDialog Private Sub InitializeComponent()Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))Me.btnPreview = New System.Windows.Forms.ButtonMe.pdocTest = New System.Drawing.Printing.PrintDocumentMe.ppdTest = New System.Windows.Forms.PrintPreviewDialogMe.SuspendLayout()''btnPreview'Me.btnPreview.Location = New System.Drawing.Point(79, 43)Me.btnPreview.Name = "btnPreview"Me.btnPreview.TabIndex = 0Me.btnPreview.Text = "Preview"''pdocTest'''ppdTest'Me.ppdTest.AutoScrollMargin = New System.Drawing.Size(0, 0)Me.ppdTest.AutoScrollMinSize = New System.Drawing.Size(0, 0)Me.ppdTest.ClientSize = New System.Drawing.Size(400, 300)Me.ppdTest.Document = Me.pdocTestMe.ppdTest.Enabled = TrueMe.ppdTest.Icon = CType(resources.GetObject("ppdTest.Icon"), System.Drawing.Icon)Me.ppdTest.Location = New System.Drawing.Point(144, 18)Me.ppdTest.MinimumSize = New System.Drawing.Size(375, 250)Me.ppdTest.Name = "ppdTest"Me.ppdTest.TransparencyKey = System.Drawing.Color.EmptyMe.ppdTest.Visible = False''Form1'Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)Me.ClientSize = New System.Drawing.Size(232, 109)Me.Controls.Add(Me.btnPreview)Me.Name = "Form1"Me.Text = "Form1"Me.ResumeLayout(False)End Sub#End RegionPrivate Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click' Convert the dialog into a Form.Dim dlg As Form = DirectCast(ppdTest, Form)' Set a "restore" size.dlg.Width = 600dlg.Height = 400' Start the dialog maximized.dlg.WindowState = FormWindowState.Maximized' Show the dialog.ppdTest.ShowDialog()End SubPrivate Sub pdocTest_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdocTest.PrintPageDim the_pen As New Pen(Color.Blue, 10)e.Graphics.DrawRectangle(the_pen, e.MarginBounds)the_pen.Dispose()e.HasMorePages = FalseEnd SubEnd Class

That's quite good for today come some days later coz me only I don't know much and I'm learning ;)

Hi traffic seeker and adsense pirates !I think that lots of you search for traffic for it's site so that spaming the whole pla(net) . Ok I'm not against especially lot of groups accept spam. and they accept it for having large traffic lol.But the thing that I mentionned well that google (this ultra big traffic) can redirect it's traffic for you!

How to upload your content to google ?First submit your site and I think that all of you have done this step, but submit it @ least to ten search engine like Yahoo, MSN, Live, Ask, Altavista...Second let's begin with Google Webmaster tools !First on it , subscribe to google web master tools and add a site profile.Then make the site verification. I'll suggest that you upload a HTML file, if you change your home page later you'll need to put the tag again !

Now we need a site map. (only if pages < href="http://www.xml-sitemaps.com/">www.xml-sitemaps.com and make a site map to your site (web based application so you want download anything with you !)

But google still doesn't index your pages or let say slowley indexes your pages.So something is going wrong... ON YOUR SITE!Your page header must be clear and well organised and will give you a sample to focus on it: the sample of SQL Warrior that I optimized for Search engine especially the forums you can see the head (http://sqlwarrior.freehostia.com) and (http://sqlwarrior.freehostia.com/forum)

See how it's organised to get an idea for your page !

wAAAk google indexed my page but i'm not the first !Dear,No one can guarantee a #1 ranking on GoogleSo how ?Now you can go to other forums and show your site but... don't spam

Many Web master face this problem.Many hits but no clicks !Ask your self somequestions @ least !Are your visitors interested on your site ?Does your site contain important information ?I know I can have 5000 hit / day but if all visitors see the first page then out !! no clicks !You 'll need to have interesting things on your site and ads won't have revenue unless 3 or 4 week or activities !

Take a look @ this tutorNo isn't me who write it all ! but just organise information found on the web

Connecting to an OLE DB Data SourceOLE DB is a specification for wrapping data sources in a COM-based API so that data sources can be accessed in a polymorphic way. The concept is the same as ADO.NET's concept of managed providers. OLE DB predates ADO.NET and will eventually be superseded by it. However, over the years, OLE DB providers have been written for many data sources, including Oracle, Microsoft Access, Microsoft Exchange, and others, whereas currently only one product--SQL Server--is natively supported by an ADO.NET managed provider. To provide immediate support in ADO.NET for a wide range of data sources, Microsoft has supplied an ADO.NET managed provider for OLE DB. That means that ADO.NET can work with any data source for which there is an OLE DB data provider. Furthermore, because there is an OLE DB provider that wraps ODBC (an even older data-access technology), ADO.NET can work with virtually all legacy data, regardless of the source.Connecting to an OLE DB data source is similar to connecting to SQL Server, with a few differences: the OleDbConnection class (from the System.Data.OleDb namespace) is used instead of the SqlConnection class, and the connection string is slightly different. When using the OleDbConnection class, the connection string must specify the OLE DB provider that is to be used as well as additional information that tells the OLE DB provider where the actual data is. For example, the following code opens a connection to the Northwind sample database in Microsoft Access:' Open a connection to the database.Dim strConnection As String = _"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _& "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"Dim cn As OleDbConnection = New OleDbConnection(strConnection)cn.Open( )Similarly, this code opens a connection to an Oracle database:' Open a connection to the database.Dim strConnection As String = _"Provider=MSDAORA.1;User ID=MyID;Password=MyPassword;" _& "Data Source=MyDatabaseService.MyDomain.com"Dim cn As OleDbConnection = New OleDbConnection(strConnection)cn.Open( )The values of each setting in the connection string, and even the set of settings that are allowed in the connection string, are dependent on the specific OLE DB provider being used. Refer to the documentation for the specific OLE DB provider for more information.Table 8-2 shows the provider names for several of the most common OLE DB providers.Table 8-2: Common OLE DB provider namesData sourceOLE DB provider nameMicrosoft AccessMicrosoft.Jet.OLEDB.4.0Microsoft Indexing ServiceMSIDXS.1Microsoft SQL ServerSQLOLEDB.1OracleMSDAORA.1Reading Data into a DataSetThe DataSet class is ADO.NET's highly flexible, general-purpose mechanism for reading and updating data. Example 8-1 shows how to issue a SQL SELECT statement against the SQL Server Northwind sample database to retrieve and display the names of companies located in London. The resulting display is shown in Figure 8-1.Figure 8-1. The output generated by the code in Example 8-1FPRIVATE "TYPE=PICT;ALT=Figure 1"Example 8-1: Retrieving data from SQL Server using a SQL SELECT statement' Open a connection to the database.Dim strConnection As String = _"Data Source=localhost; Initial Catalog=Northwind;" _& "Integrated Security=True"Dim cn As SqlConnection = New SqlConnection(strConnection)cn.Open( )' Set up a data set command object.Dim strSelect As String = "SELECT * FROM Customers WHERE City = 'London'"Dim dscmd As New SqlDataAdapter(strSelect, cn)' Load a data set.Dim ds As New DataSet( )dscmd.Fill(ds, "LondonCustomers")' Close the connection.cn.Close( )' Do something with the data set.Dim dt As DataTable = ds.Tables.Item("LondonCustomers")Dim rowCustomer As DataRowFor Each rowCustomer In dt.RowsConsole.WriteLine(rowCustomer.Item("CompanyName"))NextThe code in Example 8-1 performs the following steps to obtain data from the database:Opens a connection to the database using a SqlConnection object.Instantiates an object of type SqlDataAdapter in preparation for filling a DataSet object. In Example 8-1, a SQL SELECT command string and a Connection object are passed to the SqlDataAdapter object's constructor.Instantiates an object of type DataSet and fills it by calling the SqlDataAdapter object's Fill method.

The DataSet class encapsulates a set of tables and the relations between those tables. Figure 8-2 shows a class model diagram containing the DataSet and related classes. The DataSet is always completely disconnected from any data source. In fact, the DataSet has no knowledge of the source of its tables and relations. They may be dynamically created using methods on the DataSet, or they may be loaded from a data source. In the case of the SQL Server managed provider, a DataSet can be loaded from a SQL Server database using an SqlDataAdapter object. This is what was done in Example 8-1.Figure 8-2. A class model diagram for the DataSet and related classesFPRIVATE "TYPE=PICT;ALT=Figure 2"After a DataSet is loaded, its data can be changed, added to, or deleted, all without affecting the data source. Indeed, a database connection does not need to be maintained during these updates. When ready, the updates can be written back to the database by establishing a new connection and calling the SqlDataAdapter object's Update method. Examples of writing updates to a database are shown later in this chapter.Navigating the DataSetIn this section you'll learn how to find specific data in a DataSet object, how to make changes to that data, and how to write those changes back to a database.Finding TablesThe DataSet object's Tables property holds a TablesCollection object that contains the DataTable objects in the DataSet. The following code loops through all the tables in the DataSet and displays their names:' Iterate through the tables in the DataSet ds.Dim dt As DataTableFor Each dt In ds.TablesConsole.WriteLine(dt.TableName)NextThis code does the same thing, using a numeric index on the TablesCollection object:' Iterate through the tables in the DataSet ds.Dim n As IntegerFor n = 0 To ds.Tables.Count - 1Console.WriteLine(ds.Tables(n).TableName)NextThe TablesCollection object can also be indexed by table name. For example, if the DataSet ds contains a table named "Categories", this code gets a reference to it:Dim dt As DataTable = ds.Tables("Categories")Finding RowsThe DataTable object's Rows property holds a DataRowCollection object that in turn holds the table's DataRow objects. Each DataRow object holds the data for that particular row. The following code loops through all the rows in the DataTable and displays the value of the first column (column 0) in the row:' Iterate through the rows.Dim row As DataRowFor Each row In dt.RowsConsole.WriteLine(row(0))NextThis code does the same thing, using a numeric index on the RowsCollection object:' Iterate through the rows.Dim n As IntegerFor n = 0 To dt.Rows.Count - 1Console.WriteLine(dt.Rows(n)(0))NextTo assist with locating specific rows within a table, the DataTable class provides a method called Select. The Select method returns an array containing all the rows in the table that match the given criteria. The syntax of the Select method is:Public Overloads Function Select( _ByVal filterExpression As String, _ByVal sort As String, _ByVal recordStates As System.Data.DataViewRowState _) As System.Data.DataRow( )The parameters of the Select method are:filterExpressionThis parameter gives the criteria for selecting rows. It is a string that is in the same format as the WHERE clause in an SQL statement.sortThis parameter specifies how the returned rows are to be sorted. It is a string that is in the same format as the ORDER BY clause in an SQL statement.recordStatesThis parameter specifies the versions of the records that are to be retrieved. Record versions are discussed in the later section "Changing, Adding, and Deleting Rows." The value passed in this parameter must be one of the values given by the System.Data.DataViewRowState enumeration. Its values are:CurrentRowsReturns the current version of each row, regardless of whether it is unchanged, new, or modified.DeletedReturns only rows that have been deleted.ModifiedCurrentReturns only rows that have been modified. The values in the returned rows are the current values of the rows.ModifiedOriginalReturns only rows that have been modified. The values in the returned rows are the original values of the rows.NewReturns only new rows.NoneReturns no rows.OriginalRowsReturns only rows that were in the table prior to any modifications. The values in the returned rows are the original values.UnchangedReturns only unchanged rows.These values can be combined using the And operator to achieve combined results. For example, to retrieve both modified and new rows, pass this value:DataViewRowState.ModifiedCurrent And DataViewRowState.NewThe return value of the Select method is an array of DataRow objects.The Select method is overloaded. It has a two-parameter version that is the same as the full version, except that it does not take a recordStates parameter:Public Overloads Function Select( _ByVal filterExpression As String, _ByVal sort As String _) As System.Data.DataRow( )Calling this version of the Select method is the same as calling the full version with a recordStates value of DataViewRowState.CurrentRows.Similarly, there is a one-parameter version that takes only a filterExpression:Public Overloads Function Select( _ByVal filterExpression As String _) As System.Data.DataRow( )This is the same as calling the three-parameter version with sort equal to "" (the empty string) and recordStates equal to DataViewRowState.CurrentRows.Lastly, there is the parameterless version of Select:Public Overloads Function Select( ) As System.Data.DataRow( )This is the same as calling the three-parameter version with filterExpression and sort equal to "" (the empty string) and recordStates equal to DataViewRowState.CurrentRows.As an example of using the Select method, this line of code returns all rows whose Country column contains the value "Mexico":Dim rows( ) As DataRow = dt.Select("Country = 'Mexico'")Because the sort and recordStates parameters were not specified, they default to "" (the empty string) and DataViewRowState.CurrentRows, respectively.The Select method versus the SQL SELECT statementIf an application is communicating with a database over a fast, persistent connection, it is more efficient to issue SQL SELECT statements that load the DataSet with only the desired records, rather than to load the DataSet with a large amount of data and then pare it down with the DataTable's Select method. The Select method is useful for distributed applications that might not have a fast connection to the database. Such an application might load a large amount of data from the database into a DataSet object, then use several calls to the DataTable's Select method to locally view and process the data in a variety of ways. This is more efficient in this case because the data is moved across the slow connection only once, rather than once for each query.

Finding Column ValuesThe DataRow class has an Item property that provides access to the value in each column of a row. For example, this code iterates through all the columns of a row, displaying the value from each column (assume that row holds a reference to a DataRow object):' Iterate through the column values.Dim n As IntegerFor n = 0 To row.Table.Columns.Count - 1Console.WriteLine(row(n))NextNote the expression used to find the number of columns: row.Table.Columns.Count. The DataRow object's Table property holds a reference to the DataTable object of which the row is a part. As will be discussed shortly, the Table object's Columns property maintains a collection of column definitions for the table. The Count property of this collection gives the number of columns in the table and therefore in each row.The DataRow object's Item property is overloaded to allow a specific column value to be accessed by column name. The following code assumes that the DataRow row contains a column named "Description". The code displays the value of this column in this row:Console.WriteLine(row("Description"))Finding Column DefinitionsThe DataTable object's Columns property holds a ColumnsCollection object that in turn holds the definitions for the columns in the table. The following code iterates through the columns in the table and displays their names:' Iterate through the columns.Dim column As DataColumnFor Each column In dt.ColumnsConsole.WriteLine(column.ColumnName)NextThis code does the same thing, using a numeric index on the ColumnsCollection object:' Iterate through the columns.Dim n As IntegerFor n = 0 To dt.Columns.Count - 1Console.WriteLine(dt.Columns(n).ColumnName)NextThe ColumnsCollection object can also be indexed by column name. For example, if DataTable dt contains a column named "Description", this code gets a reference to the associated DataColumn object:Dim column As DataColumn = dt.Columns("Description")Changing, Adding, and Deleting RowsTo change data in a DataSet, first navigate to a row of interest and then assign new values to one or more of its columns. For example, the following line of code assumes that row is a DataRow object that contains a column named "Description". The code sets the value of the column in this row to be "Milk and cheese":row("Description") = "Milk and cheese"Adding a new row to a table in a DataSet is a three-step process:Use the DataTable class's NewRow method to create a new DataRow. The method takes no parameters.Set the values of the columns in the row.Add the new row to the table.For example, assuming that dt is a DataTable object, and that the table has columns named "CategoryName" and "Description", this code adds a new row to the table:' Add a row.Dim row As DataRow = dt.NewRow( )row("CategoryName") = "Software"row("Description") = "Fine code and binaries"dt.Rows.Add(row)The DataRow object referenced by row in this code can be indexed by the names "CategoryName" and "Description" because the DataRow object was created by the DataTable object's NewRow method and so has the same schema as the table. Note that the NewRow method does not add the row to the table. Adding the new row to the table must be done explicitly by calling the DataRowCollection class's Add method through the DataTable class's Rows property.Deleting a row from a table is a one-liner. Assuming that row is a reference to a DataRow, this line deletes the row from its table:row.Delete( )When changes are made to a row, the DataRow object keeps track of more than just the new column values. It also keeps track of the row's original column values and the fact that the row has been changed. The Item property of the DataRow object is overloaded to allow you to specify the desired version of the data that you wish to retrieve. The syntax of this overload is:Public Overloads ReadOnly Property Item( _ByVal columnName As String, _ByVal version As System.Data.DataRowVersion _) As ObjectThe parameters are:columnNameThe name of the column whose value is to be retrieved.versionThe version of the data to retrieve. This value must be a member of the System.Data.DataRowVersion enumeration. Its values are:CurrentRetrieve the current (changed) version.DefaultRetrieve the current version if the data has been changed, the original version if not.OriginalRetrieve the original (unchanged) version.ProposedRetrieve the proposed change. Proposed changes are changes that are made after a call to a DataRow object's BeginEdit method but before a call to its EndEdit or CancelEdit methods.For example, after making some changes in DataRow row, the following line displays the original version of the row's Description column:Console.WriteLine(row("Description", DataRowVersion.Original))The current value of the row would be displayed using any of the following lines:Console.WriteLine(row("Description", DataRowVersion.Current))Console.WriteLine(row("Description", DataRowVersion.Default))Console.WriteLine(row("Description"))Calling the DataSet object's AcceptChanges method commits outstanding changes. Calling the DataSet object's RejectChanges method rolls records back to their original versions.TIP: The code shown in this section affects only the DataSet object, not the data source. To propagate these changes, additions, and deletions back to the data source, use the Update method of the SqlDataAdapter class, as described in the next section, "Writing Updates Back to the Data Source."If there are relations defined between the DataTables in the DataSet, it may be necessary to call the DataRow object's BeginEdit method before making changes.

Writing Updates Back to the Data SourceBecause DataSets are always disconnected from their data sources, making changes in a DataSet never has any effect on the data source. To propagate changes, additions, and deletions back to a data source, call the SqlDataAdapter class's Update method, passing the DataSet and the name of the table that is to be updated. For example, the following call to Update writes changes from the DataTable named Categories back to the SQL Server table of the same name:da.Update(ds, "Categories")Before using the Update method, however, you should understand how an SqlDataAdapter object performs updates. To change, add, or delete records, an SqlDataAdapter object must send SQL UPDATE, INSERT, or DELETE statements, respectively, to SQL Server. The forms of these statements either can be inferred from the SELECT statement that was provided to the SqlDataAdapter object or can be explicitly provided to the SqlDataAdapter object.Example 8-2 shows an example of allowing an SqlDataAdapter object to infer the SQL UPDATE, INSERT, and DELETE statements required for applying updates to a database.Example 8-2: Allowing an SqlDataAdapter object to infer SQL UPDATE, INSERT, and DELETE statements from a SELECT statement' Open a database connection.Dim strConnection As String = _"Data Source=localhost;Initial Catalog=Northwind;" _& "Integrated Security=True"Dim cn As SqlConnection = New SqlConnection(strConnection)cn.Open( )' Create a data adapter object and set its SELECT command.Dim strSelect As String = _"SELECT * FROM Categories"Dim da As SqlDataAdapter = New SqlDataAdapter(strSelect, cn)' Set the data adapter object's UPDATE, INSERT, and DELETE' commands. Use the SqlCommandBuilder class's ability to auto-' generate these commands from the SELECT command.Dim autogen As New SqlCommandBuilder(da)' Load a data set.Dim ds As DataSet = New DataSet( )da.Fill(ds, "Categories")' Get a reference to the "Categories" DataTable.Dim dt As DataTable = ds.Tables("Categories")' Modify one of the records.Dim row As DataRow = dt.Select("CategoryName = 'Dairy Products'")(0)row("Description") = "Milk and stuff"' Add a record.row = dt.NewRow( )row("CategoryName") = "Software"row("Description") = "Fine code and binaries"dt.Rows.Add(row)' Delete a record.row = dt.Select("CategoryName = 'MyCategory'")(0)row.Delete( )' Update the database.da.Update(ds, "Categories")' Close the database connection.cn.Close( )Note the following in Example 8-2:A SqlDataAdapter object is constructed with an argument of "SELECT * FROM Categories". This initializes the value of the SqlDataAdapter object's SelectCommand property.A SqlCommandBuilder object is constructed with the SqlDataAdapter object passed as an argument to its constructor. This step hooks the SqlDataAdapter object to the SqlCommandBuilder object so that later, when the SqlDataAdapter object's Update method is called, the SqlDataAdapter object can obtain SQL UPDATE, INSERT, and DELETE commands from the SqlCommandBuilder object.The SqlDataAdapter object is used to fill a DataSet object. This results in the DataSet object containing a DataTable object, named "Categories", that contains all the rows from the Northwind database's Categories table.One record each in the table is modified, added, or deleted.The SqlDataAdapter object's Update method is called to propagate the changes back to the database.Step 5 forces the SqlCommandBuilder object to generate SQL statements for performing the database update, insert, and delete operations.When the Update method is called, the SqlDataAdapter object notes that no values have been set for its UpdateCommand, InsertCommand, and DeleteCommand prperties, and therefore queries the SqlCommandBuilder object for these commands. If any of these properties had been set on the SqlDataAdapter object, those values would have been used instead.The SqlCommandBuildObject can be examined to see what commands were created. To see the commands that are generated in Example 8-2, add the following lines anywhere after the declaration and assignment of the autogen variable:Console.WriteLine("UpdateCommand: " & autogen.GetUpdateCommand.CommandText)Console.WriteLine("InsertCommand: " & autogen.GetInsertCommand.CommandText)Console.WriteLine("DeleteCommand: " & autogen.GetDeleteCommand.CommandText)The auto-generated UPDATE command contains the following text (note that line breaks have been added for clarity in the book):UPDATE CategoriesSET CategoryName = @p1 , Description = @p2 , Picture = @p3WHERE ((CategoryID = @p4)AND((CategoryName IS NULL AND @p5 IS NULL) OR (CategoryName = @p6)) )Similarly, the INSERT command is:INSERT INTO Categories( CategoryName , Description , Picture )VALUES ( @p1 , @p2 , @p3)And the DELETE command is:DELETE FROM CategoriesWHERE ((CategoryID = @p1)AND((CategoryName IS NULL AND @p2 IS NULL) OR (CategoryName = @p3)) )Note the use of formal parameters (@p0, @p1, etc.) in each of these statements. For each row that is to be changed, added, or deleted, the parameters are replaced with values from the row, and the resulting SQL statement is issued to the database. The choice of which value from the row to use for which parameter is controlled by the SqlCommand object's Parameters property. This property contains an SqlParameterCollection object that in turn contains one SqlParameter object for each formal parameter. The SqlParameter object's ParameterName property matches the name of the formal parameter (including the "@"), the SourceColumn property contains the name of the column from which the value is to come, and the SourceVersion property specifies the version of the value that is to be used. Row versions were discussed in the previous section, "Changing, Adding, and Deleting Rows."If desired, a DataSet object's UpdateCommand, InsertCommand, and DeleteCommand properties can be set directly. Example 8-3 sets the value of UpdateCommand and then performs an update using this command.Example 8-3: Setting a DataSet object's UpdateCommand property' Open a database connection.Dim strConnection As String = _"Data Source=localhost;Initial Catalog=Northwind;" _& "Integrated Security=True"Dim cn As SqlConnection = New SqlConnection(strConnection)cn.Open( )' Set up a data adapter object.Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Categories", cn)' Create an UPDATE command.'' This is the command text.' Note the parameter names: @Description and @CategoryID.Dim strUpdateCommand As String = _"UPDATE Categories" _& " SET Description = @Description" _& " WHERE CategoryID = @CategoryID"'' Create a SqlCommand object and assign it to the UpdateCommand property.da.UpdateCommand = New SqlCommand(strUpdateCommand, cn)'' Set up parameters in the SqlCommand object.Dim param As SqlParameter'' @CategoryIDparam = da.UpdateCommand.Parameters.Add( _New SqlParameter("@CategoryID", SqlDbType.Int))param.SourceColumn = "CategoryID"param.SourceVersion = DataRowVersion.Original'' @Descriptionparam = da.UpdateCommand.Parameters.Add( _New SqlParameter("@Description", SqlDbType.NChar, 16))param.SourceColumn = "Description"param.SourceVersion = DataRowVersion.Current' Load a data set.Dim ds As DataSet = New DataSet( )da.Fill(ds, "Categories")' Get the table.Dim dt As DataTable = ds.Tables("Categories")' Get a row.Dim row As DataRow = dt.Select("CategoryName = 'Dairy Products'")(0)' Change the value in the Description column.row("Description") = "Milk and stuff"' Perform the update.da.Update(ds, "Categories")' Close the database connection.cn.Close( )

I forget that lots of you are lazy so I'll suggest this site (also if your server doesn't support PHP) : www.feedjit.comI use both PHP and feedjit on www.barcodemaker.uni.ccHope you like it.If you need pro and high startics why not try Google !www.google.com/analytics

About Me

Hi. My name is Dan. I am an undergraduate student studying electrical engineering and I love to blog. I started blogging and learning SEO in 2008. SEO is dynamic and it keeps updating regularly. I try my best to learn from others and share my knowledge with my readers at SABT. I hope you like my blog!

Blogroll

Disclaimer

Some of the information (stats, pictures) provided on SEO and Bloggint Tips may have been obtained from other sources. If you think I have done so without getting your (the owner’s) approval then please contact me as soon as possible and I will remove it from the blog.