In this post we have learned completely about insert or save queries. This is a very easy task. For this we have to take four number Textbox from tool box. There are two number buttons, a picture box and an open file dialog. In four boxes we will have number, name, class, address. After that we need to create a database. After that use the below coding as per video instruction. This coding is required by us in every registration software. Like online job application, any database management software etc.
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Public Class Form1
Dim cnoo As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\hp1\documents\Integrated Security=True;User Instance=True")
Dim cmddd As New SqlCommand
Dim dr As SqlDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If PictureBox1.Image IsNot Nothing Then
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
cnoo.Open()
cmded.CommandText = "insert into Table2 (Number,Name,Class,Address,Image) values (@Number,@Name,@Class,@Address,@Image)"
Dim msss As New MemoryStream()
PictureBox1.Image.Save(msss, PictureBox1.Image.RawFormat)
cmded.Parameters.AddWithValue("@number", TextBox1.Text)
cmded.Parameters.AddWithValue("@name", TextBox2.Text)
cmded.Parameters.AddWithValue("@class", TextBox3.Text)
cmded.Parameters.AddWithValue("@address", TextBox4.Text)
cmded.Parameters.AddWithValue("@image", msss.ToArray())
cmded.ExecuteNonQuery()
cnoo.Close()
TextBox2.Text = ""
TextBox2.Text = ""
TextBox2.Text = ""
TextBox2.Text = ""
PictureBox1.Image = Nothing
MessageBox.Show("Record SAVED!")
End If
Else
End If
End Sub