Hi ok so i want to read images from an sql server database..the images are saved in bytes but im struggeling to retrieve them my code for the retrieving
this is the code i used to save the image and its working.
Dim sql As String = "INSERT INTO item VALUES(@itemName, @itemCost, @itemRecipe1, @itemRecipe2, @itemRecipe3, @itemShop, @itemBonus, @pictureName, @itemPicture)"
Dim cmd As New SqlCommand(sql, sqlcon)
sqlcon.Open()
cmd.Parameters.AddWithValue("@itemName", txtItemN.Text)
cmd.Parameters.AddWithValue("@itemCost", txtCost.Text)
cmd.Parameters.AddWithValue("@itemRecipe1", txtRecipe1.Text)
cmd.Parameters.AddWithValue("@itemRecipe2", txtRecipe2.Text)
cmd.Parameters.AddWithValue("@itemRecipe3", txtRecipe3.Text)
cmd.Parameters.AddWithValue("@itemShop", txtShop.Text)
cmd.Parameters.AddWithValue("@itemBonus", txtBonus.Text)
cmd.Parameters.AddWithValue("@pictureName", txtPictureN.Text)
Dim ms As New MemoryStream()
pbItemAdd.BackgroundImage.Save(ms, pbItemAdd.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@itemPicture", SqlDbType.Image)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
this is the code i use to retrieve
Dim SQL As String = "INSERT @itemName, @itemCost, @itemRecipe1, @itemRecipe2, @itemRecipe3, @itemShop, @itemBonus, @pictureName, @itemPicture FROM item"
sqlcon.Open()
cmd = New SqlClient.SqlCommand(SQL, sqlcon)
pbItemAdd.ImageLocation = cmd.ExecuteScalar.ToString
sqlcon.Close()
but i get an error saying "Must declare the scalar variable "@itemName"." and i get this error at "pbItemAdd.ImageLocation = cmd.ExecuteScalar.ToString"
I dont even know if this code is correct.
can someone please help me and tell me what im doing wrong here and what i should actually do