Reputation: 93
I get this error →
Operator '&' is not defined for string "Insert into SP_Master_Entry (SP_" and type 'Byte()'.
I think this error is caused near dr(SP_Photo)
and am very much new to VB.NET
mainModule.DatabaseNonQuery("
Insert into SP_Master_Entry
(SP_ID, SP_Name, Gender, Date_Of_Birth, Date_Of_Join, Branch_ID,
SP_Area_ID, SP_Address1, SP_Address2, SP_Address3, PIN, Qualification,
Contact_Number, SP_Photo, SP_Status, Caste, SHG_Member, Marital_Status,
Salary, KYC_TYPE_ID, KYC_Code, Reference, Reference2, Agreement, Resigned,
ResignedDate,delivery_status,allow_edit)
VALUES (" & dr("SP_ID") & ",'" & dr("SP_Name") & "','" & dr("Gender") & "','"
& dr("Date_Of_Birth") & "','" & dr("Date_Of_Join") & "',"
& dr("Branch_ID") & "," & dr("SP_Area_ID") & ",'" & dr("SP_Address1")
& "','" & dr("SP_Address2") & "','" & dr("SP_Address3") & "',"
& dr("PIN") & "," & dr("Qualification") & ",'" & dr("Contact_Number")
& "'," & dr("SP_Photo") & ",'" & dr("SP_Status") & "','" & dr("Caste")
& "','" & dr("SHG_Member") & "','" & dr("Marital_Status") & "','"
& dr("Salary") & "'," & dr("KYC_TYPE_ID") & ",'" & dr("KYC_Code")
& "','" & dr("Reference") & "','" & dr("Reference2") & "','"
& dr("Agreement") & "','" & dr("Resigned") & "','" & dr("ResignedDate")
& "','" & dr("delivery_status") & "','" & dr("allow_edit") & "','"
& Today.Date.ToString & "','" & Today.Date.ToString & "')")
Upvotes: 0
Views: 3969
Reputation: 93
Before inserting an image.
Now use the image which you have build and use it in insert query as shown below
Dim img_b As Byte() = dr("SP_Photo")
Dim img_stream As IO.MemoryStream
img_stream = New IO.MemoryStream(img_b)
Dim img As Image = Image.FromStream(img_stream)
Dim cmd As New SqlCommand("update user_table_name set user_Photo=@image where user_ID=" & dr("SP_ID"), connstr)
cmd.Parameters.Add("@image", SqlDbType.Image, img_b.Length).Value = img_b
cmd.ExecuteNonQuery()
Upvotes: 0
Reputation: 546213
The error says it all: Byte()
(i.e. an array of bytes) is a fundamentally different type from String
and you cannot concatenate the two. How to solve this depends on what data these bytes contain and what you want to get from them. The Encoding.GetString
method may help, if the bytes contain encoded text data.
More generally, the code you posted is beyond the pale. You cannot write code like this, it’s completely unreadable and hence worthless. Refactor it.
Upvotes: 1