i am doing onine railway reservation project .i have taken a ticket booking form where user can enter passenger detail .i have taken 6 textboxes for name,dropdownlist for age,berth,sex,class. i have written following code for ticket booking but this code is not working when after entering details this code does not calculate ticket_price for particular age.please tell me if this code is wrong then tell me right code.i am using asp.net and vb.net.i am saving all the details entered by user in database.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dr As System.Data.OleDb.OleDbDataReader
Dim insert As String
Dim connectionstring As String = "provider=MSDAORA;datasource=;user id=scott;password=tiger"
Dim oledbconnection1 As Data.OleDb.OleDbConnection = New Data.OleDb.OleDbConnection(connectionstring)
oledbconnection1.Open()
Dim mycommand As Data.OleDb.OleDbCommand
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
x1 = dr.Item("reserveseats")
oledbconnection1.Close()
If (DropDownList1.SelectedValue = "ac chair class") Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
a = dr.Item("ac_chair_class")
ElseIf (DropDownList1.SelectedValue = "executive_class") Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
a = dr.Item("executive_class")
oledbconnection1.Close()
ElseIf (DropDownList1.SelectedValue = "first_class") Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
a = dr.Item("first_class")
oledbconnection1.Close()
ElseIf (DropDownList1.SelectedValue = "second_class") Then
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'")
dr = mycommand.ExecuteReader()
dr.Read()
a = dr.Item("second_class")
oledbconnection1.Close()
ElseIf (DropDownList1.SelectedValue = "third_class") Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
a = dr.Item("third_class")
oledbconnection1.Close()
End If
mycommand = New Data.OleDb.OleDbCommand("select * from ritika7", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
b = dr.Item("pnrno")
c = dr.Item("ticketno")
update = "update ritika7 set pnrno= pnrno+1 ,ticketno= ticketno+1"
mycommand = New System.Data.OleDb.OleDbCommand(update, oledbconnection1)
mycommand.ExecuteNonQuery()
oledbconnection1.Close()
If (TextBox6.Text = 1) Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + TextBox1.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
x1 = dr.Item("reserveseats")
y = x1 + 1
mycommand = New Data.OleDb.OleDbCommand("update ritika2 set reserveseats=@textbox6.text where train_id='" + TextBox1.Text + "'")
If DropDownList2.SelectedValue = "below 12 years" Then
ticket_price = 0
ElseIf DropDownList2.SelectedValue = "above 12 years" Then
ticket_price = a
ElseIf DropDownList2.SelectedValue = "above 60 years" Then
ticket_price = 67
End If
insert = "insert into reservation2 values('" + trainno.Text + "','" + trainname.Text + "','" + source.Text + "','" + destination.Text + "','" + DropDownList1.SelectedValue + "','" + date.Text + "','" + name.Text + "','" + DropDownList2.SelectedValue + "','" + DropDownList3.SelectedValue + "','" + b + "','" + c + "','" + ticket_price + "','" + y + "')"
mycommand = New System.Data.OleDb.OleDbCommand(insert, oledbconnection1)
mycommand.ExecuteNonQuery()
oledbconnection1.Close()
ElseIf (TextBox6.Text = 2) Then
oledbconnection1.Open()
mycommand = New Data.OleDb.OleDbCommand("select * from ritika2 where train_id='" + trainid.Text + "'", oledbconnection1)
dr = mycommand.ExecuteReader()
dr.Read()
x1 = dr.Item("reserveseats")
y1 = x1 + 1
y2 = y1 + 1
mycommand = New Data.OleDb.OleDbCommand("update ritika2 set reserveseats=@textbox6.text where train_id='" + TextBox1.Text + "'")
If DropDownList2.SelectedValue = "below 12 years" Then
ticket_price = 0
ElseIf DropDownList2.SelectedValue = "above 12 years" Then
ticket_price = a
ElseIf DropDownList2.SelectedValue = "above 60 years" Then
ticket_price = 67
End If
If DropDownList4.SelectedValue = "below 12 years" Then
ticket_price1 = 0
ElseIf DropDownList4.SelectedValue = "above 12 years" Then
ticket_price1 = a
ElseIf DropDownList4.SelectedValue = "above 60 years" Then
ticket_price1 = 67
End If
insert = "insert into reservation2 values('" + Trainid.Text + "','" + Trainname.Text + "','" + source.Text + "','" + destination.Text + "','" + DropDownList1.SelectedValue + "','" + date.Text + "','" + name.Text + "','" + DropDownList2.SelectedValue + "','" + DropDownList3.SelectedValue + "','" + b + "','" + c + "','" + ticket_price + "','" + y + "')"
insert = "insert into reservation2 values('" + Trainid.Text + "','" + Trainname.Text + "','" + source.Text + "','" + destination.Text + "','" + DropDownList1.SelectedValue + "','" + date.Text + "','" + name1.Text + "','" + DropDownList4.SelectedValue + "','" + DropDownList5.SelectedValue + "','" + b + "','" + c + "','" + ticket_price + "','" + y + "')"
mycommand = New System.Data.OleDb.OleDbCommand(insert, oledbconnection1)
mycommand.ExecuteNonQuery()
oledbconnection1.Close()
End If
end sub