Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

vb.net - how to use inner join in vb .net to fill textbox of vb windows form application

i am new in vb .net i am making a project airline reservation system so i have to fetch data from two tables and show in my vb form textboxs i am using inner join to fetching data from two different table but i am always getting error pls guys see my code and suggest me.here TICKET_NO,CUSTOMER_ID and FLIGHT_ID here in TICKET_RESERVATION Table and FLIGHT_CHARGES here in in FLIGHT_DETAILS Table and FLIGHT_ID column here in both TICKET_RESERVATION and FLIGHT_DETAILS Tables pls help me

I am getting error no value given for one or more required parameter

Try
    If Not con.State = ConnectionState.Open Then
        con.Open()
    End If
    Dim da As New OleDb.OleDbDataAdapter("SELECT TICKET.TICKET_NO,CUSTOMER.CUSTOMER_ID,FLIGHT.FLIGHT_ID,FLIGHT.FLIGHT_CHARGES FROM TICKET_RESERVATION INNER JOIN FLIGHT_DETAILS ON TICKET_RESERVATION.FLIGHT_ID = FLIGHT_DETAILS.FLIGHT_ID WHERE [TICKET_NO]= '" & txtTicketNo.Text & "'", con)
    Dim ds As New DataSet
    da.Fill(ds, "TICKET_RESERVATION")
    If ds.Tables("TICKET_RESERVATION").Rows.Count > 0 Then
        txtTicketNo.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(0).ToString()
        txtCustomerId.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(1).ToString()
        txtFlightId.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(2).ToString()
        txtAmount.Text = ds.Tables("FLIGHT_DETAILS").Rows(0).Item(3).ToString()

    End If
    con.Close()
Catch ex As Exception
    MsgBox(ex.Message.ToString)
End Try

now my prblem is solve but Now i am getting error Object reference not set to an instance of object i think now prblem in my this code

 Dim ds As New DataSet
        da.Fill(ds)
        If ds.Tables("TICKET_RESERVATION").Rows.Count > 0 Then
            txtTicketNo.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(0).ToString()
            txtCustomerId.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(1).ToString()
            txtFlightId.Text = ds.Tables("TICKET_RESERVATION").Rows(0).Item(2).ToString()
            txtAmount.Text = ds.Tables("FLIGHT_DETAILS").Rows(0).Item(3).ToString()

        End If
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The projection part of your Select query refers to table aliases that don't exist elsewhere in the query - such as Ticket,Customer and Flight...

Try this query instead (you can fix the SQL Injection yourself...):

SELECT TICKET.TICKET_NO,CUSTOMER.CUSTOMER_ID,FLIGHT.FLIGHT_ID,FLIGHT.FLIGHT_CHARGES FROM TICKET_RESERVATION AS TICKET INNER JOIN FLIGHT_DETAILS AS FLIGHT ON TICKET_RESERVATION.FLIGHT_ID = FLIGHT_DETAILS.FLIGHT_ID WHERE [TICKET_NO]= '" & txtTicketNo.Text & "'", con)

It'll still crash because of the CUSTOMER alias that I can't see anything for at all in your query, but I've fixed the other two... Perhaps you could take the Customer_If from the Ticket_Reservation table - I suspect it will be there...

in fact, I'll deal with that for you... Try this:

 SELECT TICKET.TICKET_NO,TICKET.CUSTOMER_ID,FLIGHT.FLIGHT_ID,FLIGHT.FLIGHT_CHARGES FROM TICKET_RESERVATION AS TICKET INNER JOIN FLIGHT_DETAILS AS FLIGHT ON TICKET.FLIGHT_ID = FLIGHT.FLIGHT_ID WHERE [TICKET.TICKET_NO]= '" & txtTicketNo.Text & "'", con) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...