Click here to Skip to main content
15,921,646 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionmove data from access to sql 2005 using ado.net Pin
playout20-Aug-06 3:42
playout20-Aug-06 3:42 
GeneralRe: move data from access to sql 2005 using ado.net Pin
Guffa20-Aug-06 4:43
Guffa20-Aug-06 4:43 
QuestionHTML Tag Pin
Socheat.Net20-Aug-06 1:28
Socheat.Net20-Aug-06 1:28 
AnswerRe: HTML Tag Pin
Guffa20-Aug-06 1:30
Guffa20-Aug-06 1:30 
GeneralRe: HTML Tag Pin
Socheat.Net23-Aug-06 16:48
Socheat.Net23-Aug-06 16:48 
AnswerRe: HTML Tag Pin
Guffa23-Aug-06 22:11
Guffa23-Aug-06 22:11 
GeneralRe: HTML Tag Pin
Socheat.Net25-Aug-06 15:19
Socheat.Net25-Aug-06 15:19 
AnswerRe: HTML Tag Pin
Guffa27-Aug-06 0:00
Guffa27-Aug-06 0:00 
QuestionDynamically Create Linkbutton Pin
JGOnline20-Aug-06 0:07
JGOnline20-Aug-06 0:07 
AnswerRe: Dynamically Create Linkbutton Pin
gnjunge20-Aug-06 0:40
gnjunge20-Aug-06 0:40 
GeneralRe: Dynamically Create Linkbutton Pin
JGOnline20-Aug-06 1:47
JGOnline20-Aug-06 1:47 
AnswerRe: Dynamically Create Linkbutton Pin
Mircea Grelus20-Aug-06 1:35
Mircea Grelus20-Aug-06 1:35 
Questionhelp needed in slideshow Pin
Pravin H19-Aug-06 22:32
Pravin H19-Aug-06 22:32 
AnswerRe: help needed in slideshow [modified] Pin
gnjunge20-Aug-06 0:53
gnjunge20-Aug-06 0:53 
GeneralRe: help needed in slideshow Pin
Pravin H20-Aug-06 21:38
Pravin H20-Aug-06 21:38 
GeneralRe: help needed in slideshow Pin
gnjunge20-Aug-06 22:59
gnjunge20-Aug-06 22:59 
QuestionSQL Server, Images and DataGrid in ASP.NET Pin
postmaster@programmingknowledge.com19-Aug-06 19:01
postmaster@programmingknowledge.com19-Aug-06 19:01 
AnswerRe: SQL Server, Images and DataGrid in ASP.NET Pin
Colin Angus Mackay19-Aug-06 21:27
Colin Angus Mackay19-Aug-06 21:27 
AnswerRe: SQL Server, Images and DataGrid in ASP.NET Pin
bgates197020-Aug-06 7:43
bgates197020-Aug-06 7:43 
This is for ASP.NET 1.1 but should be easy to convert to 2.0. The stored proc inserts the file into a blob/image field in the table.

Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Class AttachmentDB

Private Function FileFieldSelected(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As Boolean
If FileField.PostedFile Is Nothing Then Return False
If FileField.PostedFile.ContentLength = 0 Then Return False
Return True
End Function


Private Function GetByteArrayFromFileField(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As Byte()
' Returns a byte array from the passed
' file field controls file
Dim intFileLength As Integer, bytData() As Byte
Dim objStream As System.IO.Stream
If FileFieldSelected(FileField) Then
intFileLength = FileField.PostedFile.ContentLength
ReDim bytData(intFileLength)
objStream = FileField.PostedFile.InputStream
objStream.Read(bytData, 0, intFileLength)
Return bytData
End If
End Function

Private Function FileFieldType(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As String
' Returns the type of the posted file
If Not FileField.PostedFile Is Nothing Then _
Return FileField.PostedFile.ContentType
End Function

Private Function FileFieldLength(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As Integer
' Returns the length of the posted file
If Not FileField.PostedFile Is Nothing Then _
Return FileField.PostedFile.ContentLength
End Function

Private Function FileFieldFilename(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As String
' Returns the core filename of the posted file
If Not FileField.PostedFile Is Nothing Then _
Return Replace(FileField.PostedFile.FileName, _
StrReverse(Mid(StrReverse(FileField.PostedFile.FileName), _
InStr(1, StrReverse(FileField.PostedFile.FileName), "\"))), "")
End Function

Public Function InsertAttachment(ByVal fileID As Int32, ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As Int32


If Not FileFieldSelected(FileField) Then
Return -1
End If

Dim myConnection As SqlConnection = New SqlConnection(sqlconnection)
Dim myCommand As SqlCommand = New SqlCommand("uspInsertRequestAttachment", myConnection)

myCommand.CommandType = CommandType.StoredProcedure
Dim parameterID As SqlParameter = New SqlParameter("@fileID", SqlDbType.Int)
parameterID.Value = fileID
myCommand.Parameters.Add(parameterID)

Dim parameterAttachmentType As SqlParameter = New SqlParameter("@AttachmentType", SqlDbType.VarChar, 100)
parameterAttachmentType.Value = FileFieldType(FileField)
myCommand.Parameters.Add(parameterAttachmentType)

Dim parameterLength As SqlParameter = New SqlParameter("@Length", SqlDbType.Int)
parameterLength.Value = FileFieldLength(FileField)
myCommand.Parameters.Add(parameterLength)

Dim parameterUploadName As SqlParameter = New SqlParameter("@UploadName", SqlDbType.VarChar, 100)
parameterUploadName.Value = FileFieldFilename(FileField)
myCommand.Parameters.Add(parameterUploadName)

Dim parameterAttachment As SqlParameter = New SqlParameter("@Attachment", SqlDbType.Image)
parameterAttachment.Value = GetByteArrayFromFileField(FileField)
myCommand.Parameters.Add(parameterAttachment)

myConnection.Open()
myCommand.ExecuteNonQuery()

return 1

End Function

End Class


Let me know if this works for you. bgates1970
QuestionWebClient Problems Pin
bgates197019-Aug-06 11:11
bgates197019-Aug-06 11:11 
AnswerRe: WebClient Problems Pin
Guffa19-Aug-06 13:28
Guffa19-Aug-06 13:28 
GeneralRe: WebClient Problems Pin
bgates197020-Aug-06 7:33
bgates197020-Aug-06 7:33 
GeneralRe: WebClient Problems Pin
Guffa20-Aug-06 14:01
Guffa20-Aug-06 14:01 
Questionhow to get the selected text in textarea Pin
largs19-Aug-06 10:23
largs19-Aug-06 10:23 
AnswerRe: how to get the selected text in textarea Pin
Coding C#20-Aug-06 20:27
Coding C#20-Aug-06 20:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.