Join Date: Dec 10 Posts: 10 caba11 is an unknown quantity at this point (<10)
how to save binary file to database hi. i need to save files into database... i cant find why it is not working...
这是我的法典:
Public Sub importfiles(ByVal sFileName As String)
Dim cnSQL As SqlConnection
Dim cmSQL As SqlCommand
Dim strSQL
Validate form values
Read file into a stream
Dim fs As New FileStream(sFileName, FileMode.Open, FileAccess.Read)
Dim myData(fs.Length) As Byte
fs.Read(myData, 0, fs.Length)
fs.Close()
Try
Build SQL
strSQL = "insert into data_cesta(ID, cesta) values (@ID, @cesta)"
cnSQL = New SqlConnection("Data Source=.;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True;User Instance=True")
cmSQL = New SqlCommand(strSQL, cnSQL)
cmSQL.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int)).Value = ID
cmSQL.Parameters.Add(New SqlParameter("@cesta", SqlDbType.NText)).Value = myData
cmd2.Parameters.Add("@ID", SqlDbType.Int).Value = ID
cmd2.Parameters.Add("@cesta", SqlDbType.NText).Value = myData
Open connection and execute the command
cnSQL.Open()
cmSQL.ExecuteNonQuery()
Close and clean up objects
cnSQL.Close()
cmSQL.Dispose()
cnSQL.Dispose()
Catch ex As SqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
未经审判,“cmSQL.ExecuteNon Query()”——“Failed,将参数值从数据GridViewTextBoxColumn改为Int32 ”。