0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sknake
0

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.

Edited by sknake: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.