Showing posts with label DBMS. Show all posts
Showing posts with label DBMS. Show all posts

Sunday, December 25, 2011

Bulk Copy Operation


Bulk Copy Operation

This code shows you how to do bulk copy operation using C#.
string connectionString = "";
 using (SqlConnection sc = new SqlConnection(connectionString))
 {
     sc.Open();
 
     SqlCommand commandSourceData = new SqlCommand("SELECT * FROM StoresBackup;", sc);
     SqlDataReader reader =  commandSourceData.ExecuteReader();
     using (SqlConnection dc = new  SqlConnection(connectionString))
     {
         dc.Open();
         using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dc))
         {
              bulkCopy.DestinationTableName = "Stores";
              bulkCopy.WriteToServer(reader);
         }
     }
 }

Wednesday, December 7, 2011

Reading BLOG Data from the Database

Reading BLOB Data from the Database

When creating a SqlDataReader object through the ExecuteReader method to read rows that contain BLOB data, use the CommandBehavior.SequentialAccess enumerated value. Without this enumerated value, the reader pulls data from the server to the client one row at a time. If the row contains a BLOB column, this might represent a large amount of memory. By using the enumerated value, you have a finer degree of control because the BLOB data will be pulled only when referenced (for example, by means of the GetBytes method, which you can use to control the number of bytes read). This is illustrated in the following code fragment.

Writing BLOG Data to the Database



Writing BLOG Data to the Database
public void  StorePicture( string filename )
 {
   // Read the file into a byte array
   using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
   {
     byte[] imageData = new Byte[fs.Length];
     fs.Read( imageData, 0, (int)fs.Length );
   }
   using( SqlConnection conn = new SqlConnection(connectionString) )
   {
     SqlCommand cmd = new SqlCommand("StorePicture", conn);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@filename", filename );
     cmd.Parameters["@filename"].Direction = ParameterDirection.Input;
     cmd.Parameters.Add("@blobdata", SqlDbType.Image);
     cmd.Parameters["@blobdata"].Direction = ParameterDirection.Input;
     // Store the byte array within the image field
     cmd.Parameters["@blobdata"].Value = imageData;
     conn.Open();
     cmd.ExecuteNonQuery();
   conn.Close();
   }
 }

Wednesday, September 29, 2010

Database Management System (DBMS), Defination Of DBMS

 Collection of interrelated data
Set of programs to access the data
 DBMS contains information about a particular enterprise
 DBMS provides an environment that is both convenient and efficient to use.
 Database Applications:
H Banking: all transactions
H Airlines: reservations, schedules
H Universities:  registration, grades
H Sales: customers, products, purchases
H Manufacturing: production, inventory, orders, supply chain
H Human resources:  employee records, salaries, tax deductions
n Databases touch all aspects of our lives