EDN Admin
Well-known member
Hi:
Does any one knows how to insert images into sql table without using a stored procedure?
I am working on a windows form for employees profiles (vb.net) and i have a combobox and a few text boxes.
My compobox is manually conected to a database and also the other controls.
When i fill the blanks and hit save, automatically the data is saved in my db and when i look into my combobox i see the new employee name. When i select a name, every control get filled.
I have a picture box where the selected picture profile will be display. The picture will be display also when i select a name from a combobox. It will be retrieve from db table GeneralInfo Column Foto.
What i need is to include in my sql statements the code to be able to save, update and delete the image from and to db.
This is part of my insert code:
<pre style="font-family:Consolas; font-size:13; color:black; background:#cedeb1 <span style="color:blue Private <span style="color:blue Sub savenewprofileonload(<span style="color:blue ByVal sender <span style="color:blue As System.<span style="color:#2b91af Object, <span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs) <span style="color:blue Handles btn_saveprofile_onnewprofile_tap1.Click
<span style="color:blue Dim mconn <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlConnection(<span style="color:#a31515 "Data Source=(local);Initial Catalog=mydb;Integrated Security=true;")
<span style="color:blue Dim cmd <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlCommand
cmd.Connection = mconn
cmd.CommandType = <span style="color:#2b91af CommandType.Text
cmd.CommandText = <span style="color:#a31515 "insert into GeneralInfo (Name,LastName)values(" & txt_nombre.Text & <span style="color:#a31515 "," & txt_lname.Text & <span style="color:#a31515 "<span style="color:#a31515 )"
<span style="color:blue Try
mconn.Open()
cmd.ExecuteNonQuery()
<span style="color:#2b91af MessageBox.Show(<span style="color:#a31515 "Profile Saved Successfully")
<span style="color:blue Catch ex <span style="color:blue As <span style="color:#2b91af Exception
<span style="color:#2b91af MessageBox.Show(ex.Message)
<span style="color:blue Finally
mconn.Close()
<span style="color:blue End <span style="color:blue Try
<span style="color:blue End <span style="color:blue Sub[/code]
The image column name is Foto datatype varbinary(MAX)...may be it should be image datatype....
This is my select code:
<pre style="font-family:Consolas; font-size:13; color:black; background:#cedeb1 <span style="color:blue Private <span style="color:blue Sub cbox_profiles_SelectedIndexChanged(<span style="color:blue ByVal sender <span style="color:blue As System.<span style="color:#2b91af Object, <span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs) <span style="color:blue Handles cbox_profiles.SelectedIndexChanged
<span style="color:blue Try
<span style="color:blue Dim mconn <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlConnection(<span style="color:#a31515 "Data Source=(local);Initial Catalog=mydb;Integrated Security=true;")
<span style="color:blue Dim cmd <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlCommand
cmd.Connection = mconn
cmd.CommandType = <span style="color:#2b91af CommandType.Text
cmd.CommandText = <span style="color:#a31515 "SELECT Name,LastName FROM GeneralInfo where RecordId = " + cbox_profiles.SelectedValue.ToString()
<span style="color:blue Dim formda <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlDataAdapter(cmd)
<span style="color:blue Dim formds <span style="color:blue As <span style="color:blue New <span style="color:#2b91af DataSet
formda.Fill(formds, <span style="color:#a31515 "GeneralInfo")
txt_name.Text = formds.Tables(<span style="color:#a31515 "GeneralInfo").Rows(0)(<span style="color:#a31515 "Name").ToString()
txt_lname.Text = formds.Tables(<span style="color:#a31515 "GeneralInfo").Rows(0)(<span style="color:#a31515 "LastName").ToString() <br/><span style="color:blue <br/> Catch ex <span style="color:blue As <span style="color:#2b91af Exception
<span style="color:blue End <span style="color:blue Try
btn_newprofile_onload_tap1.Visible = <span style="color:blue False
btn_editprofile_oncboxselectiontap1.Visible = <span style="color:blue True
btn_newprofile_onload_tap1.Visible = <span style="color:blue True
<span style="color:blue If cbox_profiles.SelectedIndex = 0 <span style="color:blue Then
btn_editprofile_oncboxselectiontap1.Visible = <span style="color:blue False
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub[/code]
If any one can give me a hand with this i will appreciated very much.
Thanks!
<br/>
View the full article
Does any one knows how to insert images into sql table without using a stored procedure?
I am working on a windows form for employees profiles (vb.net) and i have a combobox and a few text boxes.
My compobox is manually conected to a database and also the other controls.
When i fill the blanks and hit save, automatically the data is saved in my db and when i look into my combobox i see the new employee name. When i select a name, every control get filled.
I have a picture box where the selected picture profile will be display. The picture will be display also when i select a name from a combobox. It will be retrieve from db table GeneralInfo Column Foto.
What i need is to include in my sql statements the code to be able to save, update and delete the image from and to db.
This is part of my insert code:
<pre style="font-family:Consolas; font-size:13; color:black; background:#cedeb1 <span style="color:blue Private <span style="color:blue Sub savenewprofileonload(<span style="color:blue ByVal sender <span style="color:blue As System.<span style="color:#2b91af Object, <span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs) <span style="color:blue Handles btn_saveprofile_onnewprofile_tap1.Click
<span style="color:blue Dim mconn <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlConnection(<span style="color:#a31515 "Data Source=(local);Initial Catalog=mydb;Integrated Security=true;")
<span style="color:blue Dim cmd <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlCommand
cmd.Connection = mconn
cmd.CommandType = <span style="color:#2b91af CommandType.Text
cmd.CommandText = <span style="color:#a31515 "insert into GeneralInfo (Name,LastName)values(" & txt_nombre.Text & <span style="color:#a31515 "," & txt_lname.Text & <span style="color:#a31515 "<span style="color:#a31515 )"
<span style="color:blue Try
mconn.Open()
cmd.ExecuteNonQuery()
<span style="color:#2b91af MessageBox.Show(<span style="color:#a31515 "Profile Saved Successfully")
<span style="color:blue Catch ex <span style="color:blue As <span style="color:#2b91af Exception
<span style="color:#2b91af MessageBox.Show(ex.Message)
<span style="color:blue Finally
mconn.Close()
<span style="color:blue End <span style="color:blue Try
<span style="color:blue End <span style="color:blue Sub[/code]
The image column name is Foto datatype varbinary(MAX)...may be it should be image datatype....
This is my select code:
<pre style="font-family:Consolas; font-size:13; color:black; background:#cedeb1 <span style="color:blue Private <span style="color:blue Sub cbox_profiles_SelectedIndexChanged(<span style="color:blue ByVal sender <span style="color:blue As System.<span style="color:#2b91af Object, <span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs) <span style="color:blue Handles cbox_profiles.SelectedIndexChanged
<span style="color:blue Try
<span style="color:blue Dim mconn <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlConnection(<span style="color:#a31515 "Data Source=(local);Initial Catalog=mydb;Integrated Security=true;")
<span style="color:blue Dim cmd <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlCommand
cmd.Connection = mconn
cmd.CommandType = <span style="color:#2b91af CommandType.Text
cmd.CommandText = <span style="color:#a31515 "SELECT Name,LastName FROM GeneralInfo where RecordId = " + cbox_profiles.SelectedValue.ToString()
<span style="color:blue Dim formda <span style="color:blue As <span style="color:blue New <span style="color:#2b91af SqlDataAdapter(cmd)
<span style="color:blue Dim formds <span style="color:blue As <span style="color:blue New <span style="color:#2b91af DataSet
formda.Fill(formds, <span style="color:#a31515 "GeneralInfo")
txt_name.Text = formds.Tables(<span style="color:#a31515 "GeneralInfo").Rows(0)(<span style="color:#a31515 "Name").ToString()
txt_lname.Text = formds.Tables(<span style="color:#a31515 "GeneralInfo").Rows(0)(<span style="color:#a31515 "LastName").ToString() <br/><span style="color:blue <br/> Catch ex <span style="color:blue As <span style="color:#2b91af Exception
<span style="color:blue End <span style="color:blue Try
btn_newprofile_onload_tap1.Visible = <span style="color:blue False
btn_editprofile_oncboxselectiontap1.Visible = <span style="color:blue True
btn_newprofile_onload_tap1.Visible = <span style="color:blue True
<span style="color:blue If cbox_profiles.SelectedIndex = 0 <span style="color:blue Then
btn_editprofile_oncboxselectiontap1.Visible = <span style="color:blue False
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub[/code]
If any one can give me a hand with this i will appreciated very much.
Thanks!
<br/>
View the full article