In this post we have learned completely about Update Query. How do we update the data in the SQL server database. For this we need to take four number of text boxes and one number of buttons from the toolbox. After that one has to use the coding given below as per the instruction of the video. This coding is useful in many software. As for how to change the old data, we will use the same query for that.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If TextBox1.Text = "" Then MessageBox.Show("Fill Number Box") ElseIf TextBox2.Text = "" Then MessageBox.Show("Fill Name Box") ElseIf TextBox3.Text = "" Then MessageBox.Show("Fill cnic Box") ElseIf TextBox4.Text = "" Then MessageBox.Show("Fill address Box") Else Dim cmded As New SqlCommand cmded.Connection = cnoo cmded.CommandText = ("UPDATE Table2 SET number = @number ,name = @name ,class = @class, address = @address,image = @image WHERE number = @number") Dim ms As New MemoryStream() PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat) cmded.Parameters.Add("@number", SqlDbType.Int).Value = TextBox1.Text cmded.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox2.Text cmded.Parameters.Add("@class", SqlDbType.VarChar).Value = TextBox3.Text cmded.Parameters.Add("@address", SqlDbType.VarChar).Value = TextBox4.Text cmded.Parameters.AddWithValue("@image", ms.ToArray()) cnoo.Open() cmded.ExecuteNonQuery() MessageBox.Show("Data Updated") cnoo.Close() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" PictureBox1.Image = Nothing End If End Sub
 
Top