Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 solution

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!!
 
Share this answer
 
Comments
jomachi 2-Feb-13 3:37am    
What can i put in photo parameter?
Mantu Singh 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 2-Feb-13 4:04am    
Thanks my friend
Mantu Singh 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900