|
-
May 2nd, 2015, 08:25 AM
#1
Thread Starter
Member
How to perform arithmetic operations on the database records using vb.net
Hello !
These are my two tables which are named Table1 and Table2 ( I know they aren't good names but I created them hastily)
In table1 , I have following fields
Code:
[Train_Number], [Train_Name],[Starting_point],[Destination],[Fare]
In table2 , I have
Code:
[P_Name],[Age],[Phone],[Train_Name],[Tnumber]
I want have created a ticket cancellation system in which the user enters his [Tnumber] and [Phone]and his ticket gets cancelled but I want vb to display the confirmation receipt to the user after the ticket has been cancelled . The confirmation receipt should also contain the refundable money which is 20% of the respective train of the passenger .
I think I would have to join these two tables to fetch the record [Fare] from Table1 as both the information which users enters are in Table2 . The Table2 also contains the name of the Train so , I think we can join both the tables using this field .
The problem is that I don't know how should I do this . I have searched google also but have not found anything . Please help me . This is my cancellation form code .
Code:
Imports System.Data.OleDb
Public Class Form5
Public Connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\AMEN\Documents\Railway.accdb"
Public Conn As New OleDbConnection
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Conn.ConnectionString = Connstring
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim emptyTextBoxes =
From txt In Me.Controls.OfType(Of TextBox)()
Where txt.Text.Length = 0
Select txt.Name
If emptyTextBoxes.Any Then
MsgBox("Please fill the empty feilds ")
Else
Dim okToDelete As MsgBoxResult = MsgBox("Are you sure you want to cancel your ticket?", MsgBoxStyle.YesNo)
If okToDelete = MsgBoxResult.Yes Then
Dim str As String
str = "Delete from Table2 Where Phone = '" & TextBox1.Text & "' and Tnumber= " & TextBox2.Text
Dim cmd As OleDbCommand = New OleDbCommand(str, Conn)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
Conn.Close()
MsgBox("Your Ticket Cancelled Sucessfully ! ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
ElseIf okToDelete = MsgBoxResult.No Then
End If
Form3.Show()
Me.Close()
End If
End Sub
-
May 2nd, 2015, 09:07 AM
#2
Re: How to perform arithmetic operations on the database records using vb.net
Yea, the way your tables are setup, you would need a JOIN. You could reevaluate the table structure though and not need it. As you have it, it looks like Table1 has information about a specific train ride including how much it cost. If you where to move the cost of the trip to Table2, then you have a bit more flexibility by allowing different passengers to pay different amounts (kid rate, senior rates, discounts, ect.) In doing so, you would no long need a join, since all of the information is in a single table. Insofar as doing math in SQL you should be able to do something like this...
Code:
SELECT (fare * .2) FROM table1 WHERE <someField> = <someValue>
Last edited by kebo; May 2nd, 2015 at 09:11 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 2nd, 2015, 12:27 PM
#3
Thread Starter
Member
Re: How to perform arithmetic operations on the database records using vb.net
Thank you ! Can i also display this value in the msgBox?
-
May 2nd, 2015, 12:35 PM
#4
Re: How to perform arithmetic operations on the database records using vb.net
Sure, you can show anything you want in a message box just as long as it can be displayed as a string.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|