研究了半天,仿照网上写了这样的代码,但是不能上传WORD文件,这个要怎么修改才能上传word文件?
Imports System
Imports System.Drawing
Imports System.Collections
Imports
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing.Imaging
Imports
Imports System.Data.SqlClient
Public Class Form1
Private fs As FileStream
Private ds As DataSet
Private conn As New SqlConnection("server=localhost;database=ceshi;integrated security=true;")
Private currentpos As Integer = 9
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim Opendlg As New OpenFileDialog
Opendlg.Title = "Select a picture file"
Opendlg.Filter = "(*.doc)|*doc|(*.jpg)|*.jpg"
Opendlg.ShowDialog()
lblPath.Text = Opendlg.FileName.ToString()
fs = New FileStream(Opendlg.FileName.ToString(), FileMode.Open, FileAccess.Read)
'PictureBox1.Image = Image.FromFile(Opendlg.FileName.ToString())
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlcomm As New SqlCommand
= "INSERT INTO employees (lastname,firstname,photo) VALUES (@lastname,@firstname,@photo)"
sqlcomm.Connection = conn
Dim Data(fs.Length) As Byte
fs.Read(Data, 0, Int(fs.Length))
Dim prm1 As New SqlParameter("@lastname", txtLN.Text)
Dim prm2 As New SqlParameter("@firstname", txtFN.Text)
Dim prm3 As New SqlParameter("@photo", SqlDbType.VarBinary, Int(fs.Length), ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Current, Data)
sqlcomm.Parameters.Add(prm1)
sqlcomm.Parameters.Add(prm2)
sqlcomm.Parameters.Add(prm3)
Try
conn.Open()
sqlcomm.ExecuteNonQuery() '执行插入语句
conn.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class