VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Save MS Word File In SQL Database .....

by Gehan Fernando. (13 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Mon 17th September 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Save MS Word File In SQL Database .....

API Declarations


Imports System.Data
Imports System.Data.SqlClient

' SQL Script For Database

'if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SaveDoc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
'drop procedure [dbo].[SaveDoc]
'GO

'if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[WordFile]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
'drop table [dbo].[WordFile]
'GO

'CREATE TABLE [dbo].[WordFile] (
' [WordID] [int] IDENTITY (1, 1) NOT NULL ,
' [WordName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
' [WordDoc] [binary] (50) NOT NULL
') ON [PRIMARY]
'GO

'SET QUOTED_IDENTIFIER ON
'GO
'SET ANSI_NULLS OFF
'GO

'CREATE PROC SaveDoc (@WordName NVARCHAR (50),@WordFile BINARY)
'AS
' INSERT INTO
' WordFile
' (WordName,WordDoc)
' VALUES
' (@WordName,@WordFile)
'GO
'SET QUOTED_IDENTIFIER OFF
'GO
'SET ANSI_NULLS ON
'GO

Rate Save MS Word File In SQL Database .....




    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

Download this snippet    Add to My Saved Code

Save MS Word File In SQL Database ..... Comments

No comments have been posted about Save MS Word File In SQL Database ...... Why not be the first to post a comment about Save MS Word File In SQL Database ......

Post your comment

Subject:
Message:
0/1000 characters