Author : Gehan Fernando.
Date Submitted : 9/17/2007
Category : Database
Compatibility : .NET
This code has been accessed 9170 times.
Task : Save MS Word File In SQL Database .....
Declarations
Code
Public Class Form1
Dim con As SqlClient.SqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con = New SqlClient.SqlConnection("ConnectionString")
con.Open()
Dim fstream As New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read)
Dim buf(fstream.Length) As Byte
fstream.Read(buf, 0, fstream.Length)
fstream.Flush()
fstream.Dispose()
Dim com As New SqlClient.SqlCommand()
With com
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SaveDoc"
.Parameters.Add("@WordName", SqlDbType.NVarChar, 50).Value = TextBox1.Text
.Parameters.Add("@WordFile", SqlDbType.Binary).Value = buf
.ExecuteNonQuery()
End With
com.Parameters.Clear()
com.Dispose()
con.Dispose()
MessageBox.Show("Save Successfully", "Doc", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class