Question Codes Modification

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Experts

Please modify UPDATE codes according to INSERT codes Style.

'Insert Codes
VB.NET:
                    	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
VB.NET:
			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 !! ")
I need update codes as there are insert codes
Please help
 
I would highly recommend using parametrized queries. If you right click the project inthe solution explorer, click add, click add new item. In the dialog select 'DataSet' and set up your data connections there, it uses parametrized queries automatically.
 
Back
Top