Protected Sub AddPerson(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intLength As Integer
Dim arrContent As Byte()
Dim email As String = Me.txtPersonEmail.Text.Trim
Dim gpa As String = txtGPA.Text.Trim
Dim fileName As String = FileUpload.PostedFile.FileName
Dim ext As String = fileName.Substring(fileName.LastIndexOf("."))
ext = ext.ToLower
Dim imgType = FileUpload.PostedFile.ContentType
If ext = ".jpg" Then
ElseIf ext = ".bmp" Then
ElseIf ext = ".gif" Then
ElseIf ext = "jpg" Then
ElseIf ext = "bmp" Then
ElseIf ext = "gif" Then
Else
lblStatus.Text = " فقط JPG,BMP,GIF البرنامج لا يستقبل الا الملفات ذات الأمتداد "
Exit Sub
End If
intLength = Convert.ToInt32(FileUpload.PostedFile.InputStream.Length)
ReDim arrContent(intLength)
FileUpload.PostedFile.InputStream.Read(arrContent, 0, intLength)
If Doc2SQLServer(txtPersonName.Text.Trim, arrContent, intLength, imgType, email, gpa) = True Then
lblStatus.ForeColor = Drawing.Color.Green
lblStatus.Text = "تمت عملية الحفظ بنجاح"
Else
lblStatus.ForeColor = Drawing.Color.Red
lblStatus.Text = "فشلت عملية الحفظ"
End If
' End If
End Sub
Protected Function Doc2SQLServer(ByVal title As String, ByVal Content As Byte(), ByVal Length As Integer, ByVal strType As String, ByVal Email As String, ByVal gpa As String) As Boolean
Dim cmd As SqlCommand
Dim strSQL As String
Dim connString As New SqlConnection("Data Source=ECONSQL;Initial Catalog=MA;uid=sa;pwd=sa")
strSQL = "Insert Into tblImage(imgData,imgTitle,imgType,imgLength,Email,GPA) Values(@content,@title,@type,@length,@email,@gpa)"
cmd = New SqlCommand(strSQL, connString)
cmd.CommandType = CommandType.Text
Dim paramcontent As New SqlParameter("@content", Data.SqlDbType.Image)
paramcontent.Value = Content
cmd.Parameters.Add(paramcontent)
Dim paramTitle As New SqlParameter("@title", Data.SqlDbType.VarChar)
paramTitle.Value = title
cmd.Parameters.Add(paramTitle)
Dim paramType As New SqlParameter("@type", Data.SqlDbType.VarChar)
paramType.Value = strType
cmd.Parameters.Add(paramType)
Dim paramLen As New SqlParameter("@length", Data.SqlDbType.BigInt)
paramLen.Value = Length
cmd.Parameters.Add(paramLen)
'E-Mail
Dim paramMail As New SqlParameter("@email", Data.SqlDbType.VarChar)
paramMail.Value = Email
cmd.Parameters.Add(paramMail)
'GPA
Dim paramGPA As New SqlParameter("@gpa", Data.SqlDbType.VarChar)
paramGPA.Value = gpa
cmd.Parameters.Add(paramGPA)
Try
connString.Open()
cmd.ExecuteNonQuery()
connString.Close()
Return True
Catch ex As Exception
Return False
End Try
End Functionاللهم أطل عمري وأحسن عملي واختم بالشهادة أجلي