Please great people help me look into this from scratch.
i have field definition like this:
Column Name Data Type
StaffID nvarchar(20)
Title Varchar(20)
FirstName varchar(50)
SecondName varchar(50)
Gender nvarcher(20)
ClassTeaching nvarcher(20)
PhoneNumber nvarcher(50)
Level nvercher(20)
Salary money
Passport image
Here is vb code below, and when i run it i get the error on the title of this thread:
Dim connection As SqlConnection = Nothing
'Try
Dim img As FileUpload = CType(imgUpload, FileUpload)
Dim imgByte As Byte() = Nothing
If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
'To create a PostedFile
Dim File As HttpPostedFile = imgUpload.PostedFile
'Create byte Array with file len
imgByte = New Byte(File.ContentLength - 1) {}
'force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength)
End If
' Insert the employee name and image into db
Dim conn As String = ConfigurationManager.ConnectionStrings("localConnectionString").ConnectionString
connection = New SqlConnection(conn)
connection.Open()
Dim sql As String = "INSERT INTO StaffData(StaffID,Title,FirstName,SecondName,Gender,ClassTeaching,PhoneNumber,TeachingLevel,Salary,Passport) VALUES(@StaffID,@Title,@FirstName,@SecondName,@Gender,@ClassTeaching,@PhoneNumber,@TeachingLevel,@Salary,@Passport) SELECT @@IDENTITY"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
cmd.Parameters.AddWithValue("@StaffID", txtStaffID.Text.Trim())
cmd.Parameters.AddWithValue("@Title", txtTitle.Text.Trim())
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim())
cmd.Parameters.AddWithValue("@SecondName", txtSecondName.Text.Trim())
cmd.Parameters.AddWithValue("@Gender", txtGender.Text.Trim())
cmd.Parameters.AddWithValue("@ClassTeaching", txtClassTeaching.Text.Trim())
cmd.Parameters.AddWithValue("@PhoneNumber", txtPhoneNumber.Text.Trim())
cmd.Parameters.AddWithValue("@TeachingLevel", txtTeachingLevel.Text.Trim())
cmd.Parameters.AddWithValue("@Salary", txtSalary.Text.Trim())
cmd.Parameters.AddWithValue("@Passport", imgByte)
Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())
Image1.ImageUrl = "~/ShowImage.ashx?id=" + id
lblResult.Text = String.Format("Employee ID is {0}", id)
'Catch
' lblResult.Text = "There was an error"
'Finally
connection.Close()
'End Try
End Sub