MISC

Retrieve the image content from database

When the data from image field is extracted from database it is in form of byte array.Below is the code to convert an object to a byte array-

byte[] data= (byte[])ds.Tables[0].Rows[0][0];



Check if user has clicked a check box in a datagrid

foreach (DataGridViewRow row in dataGridView1.Rows)

{

if (row.Cells[0].Value != null &&

Convert.ToBoolean(row.Cells[0].Value) == true)

{

//the user has clicked the check box..retrieve the values accordingly

} }


Restore databse from a .bak file
Execute the following command .Specify the path where .bak file is located.

RESTORE DATABASE Test

FROM DISK = <File Location>

WITH REPLACE, MOVE '<MDFFileName>' TO 'c:\Program Files\Microsoft SQL Server\CADS.MDF',

MOVE '<LDFFileName>' TO 'c:\Program Files\Microsoft SQL Server\\CADS_Log.LDF'


The <MDFFileName> and <LDFFileName> file names can be obtained by executing the follwoing query


RESTORE FILELISTONLY

FROM DISK = <File Location>

GO

Sometimes you will see an error stating no access.some other process is using the database..Execute the below command that time

Alter Database System

  SET SINGLE_USER With ROLLBACK IMMEDIATE  


 Restore database using .ldf amd .mdf files

sp_attach_db 'Database_Name','c:\backupDB.mdf','C:\backupLogs.ldf'

2 comments:

  1. Hey Nice Post, Keep Updating more question and answers
    http://allittechnologies.blogspot.com/

    ReplyDelete
  2. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Career Advisor in Mumbai

    ReplyDelete