Saturday, March 8, 2008

How to partition and format a hard disk in Windows XP

INTRODUCTION
summary
This step-by-step article describes how to partition and format a hard disk with Windows XP.Before you can install an operating system, you must first create a primary partition on the first physical hard disk (Disk 0) on your computer, and then format a file system on that partition. This partition is named the System partition. Alternatively, you can create a separate partition for the operating system on any physical hard disk. This is named the startup partition. The System partition on Disk 0 can also be used as a startup partition

MORE INFORMATION
moreinformation
Options for partitioning and formatting your hard disk
moreinformation
You can use the Microsoft Windows XP Setup program or the Fdisk and Format tools to partition and format System and startup partitions.For additional information about how to use Fdisk and Format to partition and format your hard disk, click the following article number to view the article in the Microsoft Knowledge Base:
255867 (http://support.microsoft.com/kb/255867/) How to use the Fdisk tool and the Format tool to partition or to repartition a hard disk If your computer is already running Windows XP, and you want to create partitions other than the System or the startup partitions, you can use the Windows XP Disk Management tools.For additional information about how to use the Windows XP Disk Management tools to partition and format your hard disk, click the following article number to view the article in the Microsoft Knowledge Base:
309000 (http://support.microsoft.com/kb/309000/) How to use Disk Management to configure basic disks in Windows XP
Important things to consider before you partition and format your hard disk
moreinformation
Consider the following questions before you partition and format your hard disk:
•Have you prepared the hard disk by following the manufacturer's instructions?Set the jumpers and the cabling according to the role of the hard disk (for example, master or subordinate) and make any required BIOS (or CMOS) changes. See the documentation that came with your hard disk and motherboard, or contact the manufacturers.
•What type of file system do you want to use?You can use either the FAT or NTFS file systems.For additional information about the differences between the FAT and NTFS file systems, click the following article numbers to view the articles in the Microsoft Knowledge Base: 100108 (http://support.microsoft.com/kb/100108/) Overview of FAT, HPFS, and NTFS file systems
310525 (http://support.microsoft.com/kb/310525/) Description of the FAT32 file system in Windows XP
•Does the hard disk already contain data? If yes, have you backed up all your important data?If not, back up your data before you continue. When you partition and format a hard disk, all the data on that partition is permanently deleted. You can view current partition information without deleting your data.For additional information about how to use the backup utility or the Files and Settings Transfer Wizard, click the following article numbers to view the articles in the Microsoft Knowledge Base:
320820 (http://support.microsoft.com/kb/320820/) How to use the Backup utility to back up files and folders in Windows XP Home Edition
309340 (http://support.microsoft.com/kb/309340/) How to use Backup to restore files and folders on your computer in Windows XP
293118 (http://support.microsoft.com/kb/293118/) How to use the Files and Settings Transfer Wizard
306186 (http://support.microsoft.com/kb/306186/) How to use the Files and Settings Transfer Wizard from CD-ROM
306187 (http://support.microsoft.com/kb/306187/) How to use the Files and Settings Transfer Wizard Disk in Windows XP
•Does the hard disk have a drive overlay or a disk management program?If your computer uses drive overlay software for large hard disk support, do not use the Windows XP Setup program to partition or to format the drive until you have verified Windows XP compatibility with the software manufacturer. If you do not know whether you have drive overlay software installed, contact the software manufacturer before you continue.
•Do you have the floppy disks or the CD-ROMs that you need to reinstall your software?Make sure that you have the software so that you can reinstall your programs after you partition and format your drive. If you purchased an upgrade for a program, make sure that you have the full version of the original program. Many upgrades for programs require a compliance check before you can install the upgraded product. If you cannot find the original floppy disks or CD-ROMs, contact the software manufacturer before you continue.
•Do you have updated device drivers backed up on storage other than the drive that you want to format and partition?If you have installed an updated device driver for your peripheral devices (for example, modems and printers), make sure that you back up the new driver for the device to a location other than the drive that you want to format and partition. Therefore, you can reinstall it after you install your operating system.
•Can you start your computer from the CD-ROM drive?
How to partition and format your hard disk by using the Windows XP Setup program
loadTOCNode(2, 'moreinformation');
Important If you follow these steps on a hard disk that is not empty, all the data on that hard disk is permanently deleted. We recommend that you back up your hard disk before you follow these steps.To partition and format your hard disk by using the Windows XP Setup program:
1.Insert the Windows XP CD-ROM into your CD-ROM drive or DVD-ROM drive, or insert the first Windows XP Setup disk into the floppy disk drive, and then restart the computer.Note To start your computer from the Windows XP CD-ROM (or from the startup disk), your computer must be configured to start from the CD-ROM drive, the DVD-ROM drive, or the floppy disk drive. In some cases, you may have to modify your computer's BIOS settings to set this configuration. For information about how to configure your computer to start from the CD-ROM drive, the DVD-ROM drive, or the floppy disk drive, see the documentation that is included with your computer, or contact the computer manufacturer.
2.If you are starting the computer from the Windows XP CD-ROM, select any options that are required to start the computer from the CD-ROM drive if you are prompted to do this.Note If your hard disk controller requires a third-party original equipment manufacturer (OEM) driver, press F6 to specify the driver.For more information about how to use F6 to supply a third-party OEM device driver while the Windows Setup program is running, click the following article number to view the article in the Microsoft Knowledge Base:
314859 (http://support.microsoft.com/kb/314859/) Limited OEM driver support is available with F6 during Windows XP Setup If you are starting from the Windows XP Setup disks, insert each of the additional disks when you are prompted, and then press ENTER to continue after you insert each disk.
3.At the Welcome to Setup page, press ENTER.
4.Note If you are using the Setup disks (6 bootable disks), the setup will prompt you to instert the Windows XP CD.
5.Press F8 to accept the Windows XP Licensing Agreement.
6.If an existing Windows XP installation is detected, you are prompted to repair it. To bypass the repair, press ESC.
7.All the existing partitions and the unpartitioned spaces are listed for each physical hard disk. Use the ARROW keys to select the partition or the unpartitioned space where you want to create a new partition. Press D to delete an existing partition, or press C to create a new partition by using unpartitioned space. If you press D to delete an existing partition, you must then press L (or press ENTER, and then press L if it is the System partition) to confirm that you want to delete the partition. Repeat this step for each of the existing partitions that you want to use for the new partition. When all the partitions are deleted, select the remaining unpartitioned space, and then press C to create the new partition.Note If you want to create a partition where one or more partitions already exist, you must first delete the existing partition or partitions, and then create the new partition.
8.Type the size in megabytes (MB) that you want to use for the new partition, and then press ENTER, or just press ENTER to create the partition with the maximum size.
9.Repeat Steps 4 and 5 to create additional partitions if you want them.
10.If you want to install Windows XP, use the ARROW keys to select the partition where you want to install Windows XP, and then press ENTER. If you do not want to format the partition and install Windows XP, press F3 two times to quit the Windows Setup program, and then do not follow the remaining steps. In this case, you must use a different utility to format the partition.
11.Select the format option that you want to use for the partition, and then press ENTER. You have the following options:
•Format the partition by using the NTFS file system (Quick)
•Format the partition by using the FAT file system (Quick)
•Format the partition by using the NTFS file system
•Format the partition by using the FAT file system
•Leave the current file system intact (no changes)The option to leave the current file system intact is not available if the selected partition is a new partition. The FAT file system option is not available if the selected partition is more than 32 gigabytes (GB). If the partition is larger than 2 GB, the Windows Setup program uses the FAT32 file system (you must press ENTER to confirm). If the partition is smaller than 2 GB, the Windows Setup program uses the FAT16 file system. Note If you deleted and created a new System partition, but you are installing Windows XP on a different partition, you will be prompted to select a file system for both the System and startup partitions.
12.After the Windows Setup program formats the partition, follow the instructions that appear on the screen to continue. After the Windows Setup program is completed, you can use the Disk Management tools in Windows XP to create or format more partitions.For additional information about how to use the Windows XP Disk Management tools to partition and format your hard disk, click the following article number to view the article in the Microsoft Knowledge Base:
309000 (http://support.microsoft.com/kb/309000/) How to use Disk Management to configure basic disks in Windows XP
Troubleshooting
moreinformation
For additional information about how to troubleshoot partition problems in Windows XP, click the following article numbers to view the articles in the Microsoft Knowledge Base:
316505 (http://support.microsoft.com/kb/316505/) Windows XP does not recognize all available disk space
310359 (http://support.microsoft.com/kb/310359/) Cannot view NTFS logical drive after using Fdisk
310561 (http://support.microsoft.com/kb/310561/) Maximum partition size using the FAT16 file system in Windows XP
314097 (http://support.microsoft.com/kb/314097/) How to use Convert.exe to convert a partition to the NTFS file system
301340 (http://support.microsoft.com/kb/301340/) During Setup you are unable to format a partition with a File Allocation Table format
307844 (http://support.microsoft.com/kb/307844/) How to change drive letter assignments in Windows XP
315224 (http://support.microsoft.com/kb/315224/) How to remove the Linux LILO Boot Manager
REFERENCES
loadTOCNode(1, 'references');
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
314470 (http://support.microsoft.com/kb/314470/) Definition of System partition and Boot partition
314878 (http://support.microsoft.com/kb/314878/) The default cluster size for the NTFS and FAT file systems
310525 (http://support.microsoft.com/kb/310525/) Description of the FAT32 file system in Windows XP
314081 (http://support.microsoft.com/kb/314081/) The purpose of the Boot.ini file in Windows XP For additional information about how to create and manage partitions in Windows XP, click the following article number to view the article in the Microsoft Knowledge Base:
307654 (http://support.microsoft.com/kb/307654/) How to install and use the Recovery Console in Windows XP

Thursday, March 6, 2008

Disk partitioning

Disk partitioning is the creation of divisions of a hard disk. Once a disk is divided into several partitions, directories and files can be grouped by categories such as data type and usage. Space management, access permissions and directory searching are based on the file system installed on a partition. First decide how many separate categories of data are needed and the size of each. More categories provide more control but too many become a nuisance. One scheme is to separate the operating system files from user files. Having a partition for swapping, separate from system utilities, keeps frequently used programs and data near each other. Having browser cache files in a separate partition keeps them away from other files. The frequency of update and access is an important consideration for categorizing files. Separating email from audio or photos is a good idea. Files that can be retrieved from other sources can be grouped together. Careful consideration of the size of the partition is necessary as the ability to change the size depends of the file system installed in the partition..

Now decide what file system to install in the partition. Choosing different file systems is a reason to partition the disk because each file system has different characteristics related to performance and access restrictions.
(This article gets increasingly technical at this point)
Other benefits include:
The use of multi-booting setups, which allow users to have more than one operating system on a single computer. For example, one could install Linux, Mac OS X, Microsoft Windows or others on different partitions of the same hard disk and have a choice of booting into any operating system (supported by the hardware) at power-up.
Sharing swap partitions between multiple Linux distributions, so such partitions use less hard drive space.
Protecting or isolating files, to make it easier to recover a corrupted file system or operating system installation.
Raising overall computer performance because smaller filesystems are more efficient. For instance, large hard drives with only one NTFS filesystem typically have a very large Master File Table (MFT) and it generally takes more time to read this MFT than the smaller MFTs of smaller partitions.
Higher levels of data organization, raising the user efficiency of the system, for example separate partitions dedicated to digital movie processing, photos, email mailboxes or browser cache.
Partitions may be customized to different requirements, for example, allowing for read-only partitions to protect data: if one partition is damaged, none of the other file systems are affected, and the drive's data may still be salvageable.
PC BIOS partition types
This section describes partitions as used in MS-DOS, Microsoft Windows and Linux on PC compatible computer systems; for examples of partitioning schemes used in other operating systems, see Slice (disk) and BSD disklabel.
A PC hard disk can contain either as many as four primary partitions, or 1-3 primaries and a single extended partition. Each of these partitions are described by a 16-byte entry in the Partition Table which is located in the Master Boot Record.
The "type" of a partition is identified by a 1-byte code found in its partition table entry. Some of these codes (such as 0x05 and 0x0F) may be used to indicate the presence of an extended partition, but most are used by operating systems that examine partition tables to decide if a partition contains a file system they can mount/access for reading or writing data.
Once a specific partition's type has been identified, additional information about its purpose and probable contents may be found (see: List of partition identifiers for PCs as one such resource). For example, some type codes are used to hide a partition's contents from various operating systems. However, if an OS or some partitioning tool has been programmed to also examine the boot sectors of any partition, then its file system may no longer remain hidden. (Note: There are no officially assigned partition types; thus, more than one kind of file system may lay claim to the same code value.)
Primary (or Logical)
A primary (or logical) partition contains one file system. In MS-DOS and earlier versions of Microsoft Windows systems, the first partition (C:) must be a "primary partition". Other operating systems may not share this limitation; however, this can depend on other factors, such as a PC's BIOS.
The "partition type" code for a primary or logical partition can either correspond to a file system contained within (e.g. 0x07 means either an NTFS or an OS/2 HPFS file system) or indicate the partition has a special use (e.g. code 0xBC may mean an Acronis Secure Zone and code 0x82 usually indicates a Linux swap partition). The FAT16 and FAT32 file systems have made use of quite a number of partition type codes over time due to the limits of various DOS and Windows OS versions. Though a Linux operating system may recognize a number of different file systems (ext2, ext3, reiserfs, etc.), they have all consistently used the same partition type code: 0x83 (Linux native).
[Extended
An extended partition is secondary to the primary partition(s). A hard disk may contain only one extended partition; which can then be sub-divided into logical drives, each of which is (under DOS and Windows) assigned additional drive letters.
For example, under either DOS or Windows, a hard disk with one primary partition and one extended partition, the latter containing two logical drives, would typically be assigned the three drive letters: C:, D: and E: (in that order).
See Extended Boot Record for information on the structure of an extended partition.
Compressed disks
Hard disks are sometimes compressed to create additional space. Under MS-DOS and early Windows, programs such as STACKER (DR-DOS except 6), SuperStor (DR-DOS 6), DoubleSpace, or DriveSpace (Windows 95) were used. This compression was done by creating a very large file on the partition, then storing the disk's data in this file. At startup, device drivers opened this file and assigned it a separate letter. Frequently, to avoid confusion, the original partition and the compressed drive had their letters swapped, so that the compressed disk is C:, and the uncompressed area (often containing system files) is given a higher name. (SuperStor required a separate device driver to be loaded, DEVSWAP.COM).
Versions of Windows using the NT kernel, including the most recent versions, XP and Vista, contain intrinsic disk compression capability. The use of separate compression utilities has declined sharply.
Partitioning schemes
Microsoft Windows
With Microsoft Windows, the standard partitioning scheme is to create a single active primary partition, the C: drive, where the operating system, user data, applications, and page file all reside. Some users, however, prefer to create multiple partitions so that the operating system can be stored separately from other kinds of data. Proponents of multiple partitions generally point to the benefit of being able to erase a single partition (typically the operating system itself) while retaining the other data. When used in conjunction with third-party partition management programs such as Acronis True Image, Norton Partition Magic, Norton Ghost, or specialized recovery programs that come with computers manufactured by most major manufacturers, the use of multiple partitions allows computer users to quickly recover from viruses, rootkits, and trojan horses or an otherwise damaged, corrupt or compromised operating system. Windows Vista includes an inbuilt 'Disk Management' program which allows for the creation, deletion and movement of partitions.
Unix
For Unix-based and Unix-like operating systems such as Linux and Mac OS X, the creation of separate partitions for /boot, /home, /tmp, /usr, /var, /opt, swap and all remaining files under the "/" (root directory) is possible. (The same is true for Sun operating systems, except their partitions are called slices.) Such a scheme has a number of potential advantages: if one file system gets corrupted, the rest of the data (the other file systems) stay intact, minimizing data loss; partitions can be accessed read-only and the execution of setuid files disabled thus enhancing security; performance may be enhanced due to less disk head travel. This method has the disadvantage of subdividing the drive into fixed-size partitions, so a user could run out of hard drive space in his or her /home partition, even though other partitions still have plenty of usable space. A good implementation requires the user to predict how much space each partition will need, which may be a difficult task; especially for new users. Logical Volume Management, often used in servers, increases flexibility by allowing data in volumes to expand into separate physical disks (which can be added when needed); another option is to resize existing partitions when necessary. Typical desktop systems are often comprised of a single "/" (root directory) containing the entire filesystem plus a much smaller swap partition. By default, Mac OS X systems use a single "/" (root directory) containing the entire filesystem (including the swap file) as a point of simplicity (but other setup options do exist).
Partition recovery
When a partition is deleted, in general, only its partition table entry is removed from a table; and although the data is no longer accessible, it still remains on the disk until being overwritten. Specialized recovery utilities, (such as TestDisk and gpart), can locate lost file systems and recreate a partition table which includes entries for these recovered file systems. However, some disk utilities may also overwrite a number of beginning sectors of a partition they delete. For example, if Windows Disk Management (Windows 2000/XP, etc.) is used to delete a partition, it will overwrite the first sector (relative sector 0) of the partition before removing it. It may be possible to restore a FAT32 or NTFS partition if a backup boot sector is available.

PHP::Strings - PHP count_chars() Function

Definition and Usage
The count_chars() function returns how many times an ASCII character occurs within a string and returns the information.
Syntax
count_chars(string,mode)
Parameter Description
string Required. The string to be checked
mode Optional. Specifies the return modes. 0 is default. The different return modes are:

0 - an array with the ASCII value as key and number of occurrences as value
1 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero
2 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed
3 - a string with all the different characters used
4 - a string with all the unused characters
--------------------------------------------------------------------------------

sample 1
In this example we will use count_char() with mode 1 to check the string. Mode 1 will return an array with the ASCII value as key and how
many times it occurred as value (e.g. in the example below, the ASCII value for the letter "l" is 108, and it occurs three times):
"$str = "Hello World!";
print_r(count_chars($str,1));
"?> "
The output of the code above will be:
Array
(
[32] => 1
[33] => 1
[72] => 1
[87] => 1
[100] => 1
[101] => 1
[108] => 3
[111] => 2
[114] => 1
)
Example 2
In this example we will use the count_char() with mode 3 to check the string. Mode 3 will return a string with all the different characters used:
"$str = "Hello World!";
echo count_chars($str,3);
"?> "
The output of the code above will be:
!HWdelor

Tuesday, March 4, 2008

How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual Basic .NET

Description of the Technique
The SqlDataAdapter object serves as a bridge between an ADO.NET DataSet object and a SQL Server database. SqlDataAdapter is an intermediary object that populates an ADO.NET DataSet object with data that is retrieved from a SQL Server database and then updates the database to reflect the changes (such as inserts, updates, and deletes) that are made to the data by using the DataSet object.The InsertCommand, the UpdateCommand, and the DeleteCommand properties of the SqlDataAdapter object update the database with the data modifications that are run on a DataSet object.

These properties are SqlCommand objects that specify the INSERT, the UPDATE, and the DELETE Transact-SQL commands that are used to post the dataset modifications to the target database. The SqlCommand objects that are assigned to these properties can be created manually in code or automatically generated by using the SqlCommandBuilder object.The first code sample in this article demonstrates how to use the SqlCommandBuilder object to automatically generate the UpdateCommand property of the SqlDataAdapter object. The second sample uses a scenario in which you cannot use automatic command generation. The second sample demonstrates how to manually create and use a SqlCommand object as the UpdateCommand property of a SqlDataAdapter object.
Create the Sample SQL Server Table
To create a sample SQL Server table that you can use in the Visual Basic .NET code samples that are documented in this article, follow these steps:
1.Open SQL Query Analyzer, and then connect to the database in which you want to create the sample table. The code samples in this article use the Northwind database that is included with SQL Server.
2.To create a sample table that is named CustTest and to insert a record into the table, run the following Transact-SQL statements:Create Table CustTest
(
CustID int primary key,
CustName varchar(20)
)
Insert into CustTest values(1,'John')

Code Sample 1: Automatically Generated Commands
If the SELECT statement that you use to retrieve the data that populates a DataSet is based on a single database table, you can use the CommandBuilder object to automatically generate the DeleteCommand, the InsertCommand, and the UpdateCommand properties of the DataAdapter. This simplifies and reduces the code that is required to perform INSERT, UDPATE, and DELETE operations.As a minimum requirement, you must set the SelectCommand property to generate commands automatically. The table schema that the SelectCommand retrieves determines the syntax of the INSERT, the UPDATE, and the DELETE statements that are automatically generated.The SelectCommand must also return at least one primary key or unique column. If none are present, an InvalidOperation exception is generated, and the commands are not generated.To create a sample Visual Basic .NET console application that demonstrates how to use the SqlCommandBuilder object to automatically generate the DeleteCommand, the InsertCommand, and the UpdateCommand properties of the SqlCommand object for a SqlDataAdapter object, follow these steps:
1.To create a new Visual Basic .NET console application, follow these steps:
a.Start Microsoft Visual Studio .NET.
b.On the File menu, point to New, and then click Project.
c.Click Visual Basic Projects under Project Types, and then click Console Application under Templates.
2.Replace the default contents of Module1 with the following code:Imports System.Data.SqlClient
Imports Console = System.Console
Module Module1
Sub Main()
Dim cn As New SqlConnection()
Dim CustomersDataSet As New DataSet()
Dim da As SqlDataAdapter
Dim dr As DataRow
Dim cmdBuilder As SqlCommandBuilder

'Set the connection string of the SqlConnection object to connect to the
'SQL Server database in which you created the sample table.
cn.ConnectionString = "Server=.;Database=northwind;UID=sa;PWD=;"
cn.Open()

'Initialize the SqlDataAdapter object by specifying a Select command
'that retrieves data from the sample table.
da = New SqlDataAdapter("select * from CustTest order by CustId", cn)
'Initialize the SqlCommandBuilder object to automatically generate and initialize
'the UpdateCommand, InsertCommand and DeleteCommand properties of the SqlDataAdapter.
cmdBuilder = New SqlCommandBuilder(da)
'Populate the dataset by running the Fill method of the SqlDataAdapter.
da.Fill(CustomersDataSet, "Customers")

'Display the Update, Insert and Delete commands that were automatically generated
'by the SqlCommandBuilder object.
Console.WriteLine("Update command Generated by the Command Builder : ")
Console.WriteLine("==================================================")
Console.WriteLine(cmdBuilder.GetUpdateCommand.CommandText)
Console.WriteLine(" ")
Console.WriteLine("Insert command Generated by the Command Builder : ")
Console.WriteLine("==================================================")
Console.WriteLine(cmdBuilder.GetInsertCommand.CommandText)
Console.WriteLine(" ")
Console.WriteLine("Delete command Generated by the Command Builder : ")
Console.WriteLine("==================================================")
Console.WriteLine(cmdBuilder.GetDeleteCommand.CommandText)
Console.WriteLine(" ")
'Write out the value in the CustName field before updating the data using the DataSet.
Console.WriteLine("Customer Name before Update : " & CustomersDataSet.Tables("Customers").Rows(0)("CustName"))
'Modify the value of the CustName field.
CustomersDataSet.Tables("Customers").Rows(0)("CustName") = "Jack"
'Post the data modification to the database.
da.Update(CustomersDataSet, "Customers")
Console.WriteLine("Customer Name updated successfully")
'Close the database connection.
cn.Close()
Console.ReadLine()
End Sub
End Module
3.Save and then run the application. A console window opens and displays the following output:
Update command Generated by the Command Builder :
==================================================
UPDATE CustTest SET CustID = @p1 , CustName = @p2 WHERE ( CustID = @p3 AND CustName = @p4 )

Insert command Generated by the Command Builder :
==================================================
INSERT INTO CustTest( CustID , CustName ) VALUES ( @p1 , @p2 )

Delete command Generated by the Command Builder :
==================================================
DELETE FROM CustTest WHERE ( CustID = @p1 AND CustName = @p2 )

Customer Name before Update : John
Customer Name updated successfully

4.Press any key to dismiss the console window and to stop the application.
Sample 2: Manually Create and Initialize the UpdateCommand Property
The output that Code Sample 1 generates indicates that the logic to generate commands automatically for UPDATE statements is based on optimistic concurrency. That is, records are not locked for editing, and other users or processes can modify records whenever.Because a record can be modified after it is returned from the SELECT statement but before the UPDATE statement is issued, the UPDATE statement that is automatically generated contains a WHERE clause so that a row is updated only if it contains all of the original values. This is to avoid overwriting new data. If an UPDATE statement that is automatically generated tries to update a row that has been deleted or does not contain the original values that are found in the DataSet, the command does not affect any records, and a DBConcurrencyException exception is generated. To test this with the code in Code Sample 1, run the code in the Visual Studio Debugger, set a breakpoint after the DataSet has been filled but before the database is updated, and then delete the one row in the table from SQL Query Analyzer. The Update call then throws the exception.If you want the UPDATE statement to complete regardless of original values, you must explicitly set the UpdateCommand for the DataAdapter and not rely on automatic command generation. To manually create and initialize the UpdateCommand property of the SqlDataAdapter object that is used in Code Sample 1, follow these steps:
1.Replace the existing code in Sub Main of Module1 in the Visual Basic .NET console application that you created in the Code Sample 1: Automatically Generated Commands section with the following code:Dim cn As New SqlConnection()
Dim CustomersDataSet As New DataSet()
Dim da As SqlDataAdapter
Dim dr As DataRow
Dim DAUpdateCmd As SqlCommand
cn.ConnectionString = "Server=.;Database=northwind;UID=sa;PWD=;"
cn.Open()
da = New SqlDataAdapter("select * from CustTest order by CustId", cn)
'Initialize the SqlCommand object that will be used as the DataAdapter's UpdateCommand.
'Note that the WHERE clause uses only the CustId field to locate the record that is to be updated.
DAUpdateCmd = New SqlCommand("Update CustTest set CustName = @pCustName where CustId = @pCustId", da.SelectCommand.Connection)
'Create and append the parameters for the Update command.
DAUpdateCmd.Parameters.Add(New SqlParameter("@pCustName", SqlDbType.VarChar))
DAUpdateCmd.Parameters("@pCustName").SourceVersion = DataRowVersion.Current
DAUpdateCmd.Parameters("@pCustName").SourceColumn = "CustName"
DAUpdateCmd.Parameters.Add(New SqlParameter("@pCustId", SqlDbType.Int))
DAUpdateCmd.Parameters("@pCustId").SourceVersion = DataRowVersion.Original
DAUpdateCmd.Parameters("@pCustId").SourceColumn = "CustId"
'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.
da.UpdateCommand = DAUpdateCmd
da.Fill(CustomersDataSet, "Customers")
Console.WriteLine("Customer Name before Update : " & CustomersDataSet.Tables("Customers").Rows(0)("CustName"))
CustomersDataSet.Tables("Customers").Rows(0)("CustName") = "Jack"
da.Update(CustomersDataSet, "Customers")
Console.WriteLine("Customer Name updated successfully")
cn.Close()
Console.ReadLine()

Sunday, March 2, 2008

Content Building

We're going to take a break from programming and concentrate on another aspect of being a webmaster that we've mentioned once before in this series of articles and that's content. Content is going to be different for every site as each site contains different information as each site will deal with different main subjects. So the first thing I’d like to go over is how to determine the type of content we're going to use in our own sites.

First things first, we must fist decide what the site will be geared towards. Many webmasters make a common mistake; which sometimes isn't a mistake at all, but most webmasters tend to gear their sites toward more then one main topic or subject. In most cases a website is run by one webmaster and is normally a hobby or something they will do in their free time. So it's harder for most webmasters to keep a site updated the way it needs to be with more then one main topic or subject.
So if a site is ran by just one webmaster or a smaller group of webmasters, it's a good idea to keep the main topic for the site to just one thing and then branch out from that main topic. Many webmasters are unaware that a site dealing with specific information will tend to be more popular then a site dealing with a multitude of information and topics, these types of sites are also referred to as portals. For instance a site like MSN would be considered a portal and a very good portal at that. The only reason a site like MSN can pull a portal site off, is because they have the resources and man power to do it. Smaller sites can't even begin to keep up with a site of that magnitude.
Pick a Topic
Deciding what a site will be about is one of the most aggravating things for a webmaster to decide. Many times a site will need to be geared toward a main subject that can be added or branched out from. So it shouldn't be too specific, unless that is the type of site the webmaster would like to build. When deciding the main topic or subject a site there are few things the webmaster must take into consideration.
1. What are they good at and what type of information do they know a lot about?2. What types of information is easiest for them to teach others?3. Which would be fun for the webmaster producing the site?
These are just a few questions we must ask ourselves before we even begin to start a website or content for a website.
Once we have a good topic picked out that we will be able to build a site on, we can then start thinking about the type of content that we’ll fill the site with. A good rule of thumb is to pick a topic you know well so when it’s time to start writing content for the site it will not become a problem or be overly hard to do.
Build Content
Now that we know what we want to make a web site about, we now need to start determining the type of content we’re going to develop for the site. First we must decide the type of content we’ll be displaying on the site, and then we can start working on the content. So let’s take a look at a few different types of content we can put on the site.
Message Boards - Databases (Links, Downloads, Lists)
Message boards and databases are just a few examples of this form of content, which I like to call builder content. Builder content is the type of content that helps support the main content and builds it up; we’ll go over main content next. Any type of content that doesn’t take much time to do, or is a sort of add-on to existing content can be labeled as builder content and should never be used or considered main content.
Main Content
The main content to a web site would be the main focus of the site, for instance the articles on Webmaster Stop would be considered main content and the referrals or links to other resources similar would be considered builder content. Be sure to keep these two types of content in mind when building content for your own site.
We now know the different types of content and we’ve also decided what our site will be about, from this point we can actually start building content for the site. This part of building a web site can get confusing to some webmasters, as they like to get a site finished and then start adding content to it. This IS NOT the best route to take and will end up hurting the site in the long run.
Keep in mind that if we build content before any sort of design or management system is completed, we’ll be able to focus more on the content and build it to what it should be and then model the site around the content. This is always the best route to take with building any site and yes there are some sites that have exceptions but if the site is content driven then it is not an exception.