


For a detailed view of the INSERT INTO T-SQL statement, check the Microsoft INSERT INTO documentation. The INSERT INTO T-SQL statement has a dynamic syntax that fits all types of data insertion processes. This can be done by providing constant values in the INSERT INTO statement or provide the source table or view from which we will copy the rows. The INSERT INTO T-SQL statement is used mainly to add one or more rows to the target table or view in SQL Server. The T-SQL language is a rich database programming language that provides us with a large number of dynamic statements and functions that help us to perform any functionality in different ways, based on our development skills. Imports System.IOPublic Class Form1ĝim fName As Stringĝim cnn As SqlConnectionĝim connectionString As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click connectionString = "Data Source=servername Initial Catalog=databasename User ID=sa Password=password" cnn = New SqlConnection(connectionString) fName = "D:\picfile.jpg" If File.Exists(fName) Then Dim id As Integer = 1 Dim content As Byte() = ImageToStream(fName) cnn.Open() Dim cmd As New SqlCommand("insert into imgtable (id,img) values ( cnn) id) content) cmd.ExecuteNonQuery() cnn.Close() MsgBox("Image inserted") Else MsgBox(fName & " not found ") End IfĞnd Sub Private Function ImageToStream(ByVal fileName As String) As Byte() Dim stream As New MemoryStream()tryagain: Try Dim image As New Bitmap(fileName) image.Save(stream, .Jpeg) Catch ex As Exception GoTo tryagain End Try Return Stream.In this article, we will go deeply through the INSERT INTO statement by showing the different syntax formats and usage scenarios for that statement. The following VB.NET source code read the image from physical path D:\picfile.jpg and stores it to a byte array and then insert it into database. The above scrip will create a table named as imgtable and adding two column, first column is id ,an integer datatype and second column is image, an image(img) datatype. The following sql script help you to create a table with Image Datatype column : The following VB.NET program shows how to insert an Image in SQL Server.įirst you have to create a table that contain an image column.


Image is a Datatype in SQL Server that stores variable length binary data from 0 through 2A31-1 (2,147,483,647) bytes. SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server. ADO.NET provides database connectivity between relational and non relational systems through a common set of components.
