Click here to Skip to main content
15,895,709 members

update images in sqlserver using vb

beniv asked:

Open original thread
my db table is tbltest with id(int),name(varchar),lastname(varchar),foto(datatype image)
i can insert data in my database but i don't now to update them
i have store data in my db ,and i will to update them with a button (update)
the code for my insert button is

VB
cmdtabela1 = connetion.CreateCommand
                  cmdtabela1.CommandText = "insert into tbltest values (@name,@lastname,@foto) "

                  cmdtabela1.Parameters.AddWithValue("name", txtname.Text)
                  cmdtabela1.Parameters.AddWithValue("lastname", txtlastname.Text)
                  


                  Dim ms As New MemoryStream()
                  PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
                  Dim data As Byte() = ms.GetBuffer()
                  Dim p As New SqlParameter("foto", SqlDbType.Image)
                  p.Value = data
                  cmdtabela1.Parameters.Add(p)


now how to update this colums in my database

i have write this code for my update button

VB
connetion = New SqlConnection("my conetion string")
                    connetion.Open()

                    Dim ms As New MemoryStream()
                    PictureBox3.BackgroundImage.Save(ms, PictureBox3.BackgroundImage.RawFormat)
                    Dim data As Byte() = ms.GetBuffer()
                    Dim p As New SqlParameter("Foto", SqlDbType.Image)
                    p.Value = data
                    cmdtabela.Parameters.Add(p)

                    cmdtabela = connetion.CreateCommand
                    cmdtabela.CommandText = "update tbltest set name='" & txtupdatename.Text & "', lastname='" & txtupdatelstname.Text &   where Id='" & Trim(txtid.Text) & "'"
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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