Dear Experts

Please modify UPDATE codes according to INSERT codes Style.

'Insert Codes

Dim cmd As New SqlClient.SqlCommand("Insert Into employees (sno,Name, city, phone,img) Values (@sno,@Name, @city,@phone, @img)", con)
                    	cmd.Parameters.Add(New SqlClient.SqlParameter("@sno", SqlDbType.Int)).Value = Val(Me.TextBox1.Text)
                    	cmd.Parameters.Add(New SqlClient.SqlParameter("@name", SqlDbType.VarChar)).Value = Trim(Me.TextBox2.Text)
                    	cmd.Parameters.Add(New SqlClient.SqlParameter("@city", SqlDbType.VarChar)).Value = Trim(Me.TextBox3.Text)
                    	cmd.Parameters.Add(New SqlClient.SqlParameter("@phone", SqlDbType.VarChar)).Value = Trim(Me.TextBox4.Text)
                    	cmd.Parameters.Add(New SqlClient.SqlParameter("@img", SqlDbType.Image)).Value = IO.File.ReadAllBytes(PictureBox1.ImageLocation)
                    	cmd.ExecuteNonQuery()
                    	MsgBox("Record inserted !! ")

'Update Codes

str = "UPDATE employees SET name = ' " & Trim(TextBox2.Text) & "',"
                    	str &= "city =  '" & Trim(TextBox3.Text) & "',"
                    	str &= "phone= '" & Trim(TextBox4.Text) & "',"
                    	str &= "img='arr_image' "
                    	str &= " where sno = " & Val(TextBox1.Text)
                    	ExecuteQuery(str)
                    	MsgBox("Record updated !! ")

Please help

As long as you arent changing the "sno" column:

Dim cmd As New SqlClient.SqlCommand("Update employees Set Name = @Name, City = @City, Phone = @Phone, Img = @Img Where sno = @sno", con)
cmd.Parameters.Add(New SqlClient.SqlParameter("@sno", SqlDbType.Int)).Value = Val(Me.TextBox1.Text)
cmd.Parameters.Add(New SqlClient.SqlParameter("@name", SqlDbType.VarChar)).Value = Trim(Me.TextBox2.Text)
cmd.Parameters.Add(New SqlClient.SqlParameter("@city", SqlDbType.VarChar)).Value = Trim(Me.TextBox3.Text)
cmd.Parameters.Add(New SqlClient.SqlParameter("@phone", SqlDbType.VarChar)).Value = Trim(Me.TextBox4.Text)
cmd.Parameters.Add(New SqlClient.SqlParameter("@img", SqlDbType.Image)).Value = IO.File.ReadAllBytes(PictureBox1.ImageLocation)
cmd.ExecuteNonQuery()
MsgBox("Record updated !! ")

You also probably want to omit the "img" field from the update unless you are actually changing the image. BLOB fields are large so there is no reason to add the overhead of transferring the image if it is unchanged.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.