Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hello my friends
I have this query and i want to store an image to sql server database
Dim cmd As New SqlCommand()
cmd.CommandText = "INSERT INTO Staff(Lastname,Firstname,Fathername,Birthday,City,Phone,Photo)" & _
"VALUES (@Lastname,@Firstname,@Fathername,@Birthday,@City,@Phone,,@Photo)"
With cmd.Parameters
.Add(New SqlParameter("@Lastname", txtLname.Text))
.Add(New SqlParameter("@Firstname", txtFname.Text))
.Add(New SqlParameter("@Fathername", txtFtname.Text))
.Add(New SqlParameter("@Birthday", txtBdate.Text))
.Add(New SqlParameter("@City", txtCity.Text))
.Add(New SqlParameter("@Phone", txtPhone.Text))
.Add(New SqlParameter("@Photo", What in this?))
Can anyone know how?
Thanks in advance
Posted 1-Feb-13 21:31pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The error is here
VALUES (@Lastname,@Firstname,@Fathername,@Birthday,@City,@Phone,,@Photo)
//use as below remove the extra comma

VALUES (@Lastname,@Firstname,@Fathername,@Birthday,@City,@Phone,@Photo)
And about that parameter
Add(New SqlParameter("@Photo", What in this?))
it will probably be a byte array you would create from image file you need to store
Best of luck!!
jomachi at 2-Feb-13 3:37am
What can i put in photo parameter?
Mantu Singh at 2-Feb-13 3:50am
You need to create a byte array as I hope in the database you column datatype will be varbinary or image where you need the bytes of image
byte [] img=File.ReadAllBytes("image name");
Add(New SqlParameter("@Photo",img));
Remove semicolon as it wont work in VB
jomachi at 2-Feb-13 4:04am
Thanks my friend
Mantu Singh at 2-Feb-13 4:14am
Pls be kind to accept the answer too ! welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 vikinghunter 168
4 OriginalGriff 166
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788

Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100