Category Archives: SQL Server Tutorial

Microsoft SQL Server Tutorials For Beginners, free microsoft sql server tutorial, Authorcode SQL Server tutorial covers the basic concepts of the SQL server with the examples. You can learn the SQL server basic and advanced techniques and how to use sql queries from this tutorial.

Code for saving image in Sql Table in

The following code describe how to save an image file into SQL Server database. In the first code So, first take the image from the file in FileStream then convert into byte array. After that this byte array passes to the sql query as a parameter and then executes the SQL Command that insert the byte array in the image type SQL column.

Function for converting image into Byte array
Continue reading Code for saving image in Sql Table in

Code Snippet for detaching SQL database programmatically in

Following code is for detaching sql database programmatically

VB.Net Code :

Dim conn As SqlClient.SqlConnection

        Dim cmd As New SqlClient.SqlCommand()

        Dim ConnectionString As String = “Data Source=” & Server name & “;Initial Catalog=master;Integrated Security=True”  ‘ Connection string

        conn = New SqlClient.SqlConnection

        conn.ConnectionString = ConnectionString

        conn.Open()   ‘Open connection

        Dim sqlDetech As String = “sp_detach_db ‘”& database name &”‘, ‘true'”  ‘ Sql query for detaching database

        cmd.CommandText = sqlDetech

        cmd.Connection = conn

        cmd.ExecuteNonQuery()  ‘execute query