In this post you can learn Customer Registration Form Visual Basic SQL Server - Billing Software copy the below coding then paste to following places
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Imports System.Configuration
Public Class custform
Sub filterrecords(ByVal sender As String)
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM Table1"
Dim da = New SqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Dim connectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\pc1\Documents\Visual Studio 2010\Projects\billing software\billing software\Database2.mdf;Integrated Security=True;User Instance=True"
Dim cn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand
Dim dr As SqlDataAdapter
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
Form1.Enabled = True
Form1.Show()
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox9.Visible = False
TextBox8.Text = Val(TextBox6.Text) - Val(TextBox2.Text)
TextBox7.Text = Val(TextBox8.Text) + Val(TextBox5.Text) + Val(TextBox9.Text)
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
TextBox7.Text = Val(TextBox8.Text) + Val(TextBox5.Text) + Val(TextBox9.Text)
TextBox9.Visible = False
End Sub
Private Sub custform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filterrecords("")
TextBox8.Visible = False
TextBox6.Visible = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MessageBox.Show("Fill the Box")
ElseIf TextBox3.Text = "" Then
MessageBox.Show("Fill cnic Box")
ElseIf TextBox4.Text = "" Then
MessageBox.Show("Fill the Box")
ElseIf TextBox7.Text = "" Then
MessageBox.Show("Fill the Box")
Else
Dim cmd As New SqlCommand
cmd.Connection = cn
cmd.CommandText = ("UPDATE Table1 SET Business_Name = @Business_Name ,Mob_No = @Mob_No ,Address = @Address, Loan_Balance = @Loan_Balance WHERE Business_Name = @Business_Name")
cmd.Parameters.Add("@Business_Name", SqlDbType.VarChar).Value = TextBox4.Text
cmd.Parameters.Add("@Mob_No", SqlDbType.Int).Value = TextBox1.Text
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = TextBox3.Text
cmd.Parameters.Add("@Loan_Balance", SqlDbType.Decimal).Value = TextBox7.Text
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
filterrecords("")
' Clear all the TextBoxes on the form.
For Each ctl In Controls
If TypeOf ctl Is TextBox Then ctl.Text = ""
Next ctl
MessageBox.Show("Data successfully Updated")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("Fill the Box")
ElseIf TextBox3.Text = "" Then
MessageBox.Show("Fill cnic Box")
ElseIf TextBox4.Text = "" Then
MessageBox.Show("Fill the Box")
ElseIf TextBox1.Text = "" Then
Else
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM Table1 WHERE Business_Name='" & TextBox4.Text & "'"
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() > 0 Then
MessageBox.Show("Number Already Available! Go to Search Then Update")
Else
Dim cmd As New SqlCommand
cmd.Connection = cn
cn.Open()
cmd.CommandText = "insert into Table1 (Business_Name,Mob_No,Address,Loan_Balance) values (@Business_Name,@Mob_No,@Address,@Loan_Balance)"
Dim ms As New MemoryStream()
cmd.Parameters.AddWithValue("@Business_Name", TextBox4.Text)
cmd.Parameters.AddWithValue("@Mob_No", TextBox1.Text)
cmd.Parameters.AddWithValue("@Address", TextBox3.Text)
cmd.Parameters.AddWithValue("@Loan_Balance", TextBox7.Text)
cmd.ExecuteNonQuery()
cn.Close()
filterrecords("")
' Clear all the TextBoxes on the form.
For Each ctl In Controls
If TypeOf ctl Is TextBox Then ctl.Text = ""
Next ctl
MessageBox.Show("Record SAVED!")
End If
End If
End Sub
Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim index As Integer
index = e.RowIndex
Dim selectedRow As DataGridViewRow
selectedRow = DataGridView1.Rows(index)
TextBox4.Text = selectedRow.Cells(0).Value.ToString()
TextBox1.Text = selectedRow.Cells(1).Value.ToString()
TextBox3.Text = selectedRow.Cells(2).Value.ToString()
TextBox7.Text = selectedRow.Cells(3).Value.ToString()
TextBox9.Text = selectedRow.Cells(3).Value.ToString()
TextBox9.Visible = True
End Sub
End Class