object reference not set to an instance???

L

labelle

this is driving me nuts, and i can't figure it out: i am creating a
mapper that updates two tables at the same time, one with "ticket
order" information, and the other with "ticket" information. for
example, if someone orders 2 tickets, 1 order is placed into the order
table, and 2 tickets are placed into the tickets table.

however, nothing is working out.

Public Sub AddTicketOrders(ByVal TicketOrder As TicketRequest)
Dim parameters As New ArrayList
parameters.Add((New SqlParameter("@ticketName",
TicketOrder.TicketName)))
parameters.Add((New SqlParameter("@ticketStreet",
TicketOrder.TicketStreet)))
parameters.Add((New SqlParameter("@ticketCity",
TicketOrder.TicketCity)))
parameters.Add((New SqlParameter("@ticketState",
TicketOrder.TicketState)))
parameters.Add((New SqlParameter("@ticketZip",
TicketOrder.TicketZip)))
parameters.Add((New SqlParameter("@ticketCountry",
TicketOrder.TicketCountry)))
parameters.Add((New SqlParameter("@ticketPhone",
TicketOrder.TicketPhone)))
parameters.Add((New SqlParameter("@ticketFax",
TicketOrder.TicketFax)))
parameters.Add((New SqlParameter("@ticketEmail",
TicketOrder.TicketEmail)))
parameters.Add((New SqlParameter("@ticketQty",
TicketOrder.TicketQty)))
parameters.Add((New SqlParameter("@ticketConfirmKey",
TicketOrder.TicketConfirmKey)))
parameters.Add((New SqlParameter("@ticketConfirm",
TicketOrder.TicketConfirm)))
RunStoredProc("dbo.AddTicketRequest", parameters)

Dim tmpTicket As OrderedTicket
Dim ticketParams As New ArrayList
Dim i As Integer = 0
For i = 0 To TicketOrder.TicketQty
ticketParams.Add((New SqlParameter("@orderID",
tmpTicket.OrderID)))
ticketParams.Add((New SqlParameter("@ticketID",
tmpTicket.TicketID)))
RunStoredProc("dbo.AddTicket", ticketParams)
Next
End Sub

however, i keep getting an "Object reference not set to an instance of
an object" error. It's been driving me nuts all night. Can someone
please tell me what i'm doing wrong? I'm sure it's something plain as
day.

And before you ask, yes...TicketOrder.TicketQty is declared as an
integer.
 
S

Stephany Young

Firstly, tmpTicket is never being instantiated. It would appear that you
mean to assign something to tmpTicket at the start of each iteration of the
loop.

Secondly, in your example of 1 order, 2 tickets, do you expect
TicketOrder.TicketQty to have the value 1 or 2?

If it is the former then your loop controller is correct (0 To 1 = 2
iterations).

If it is the latter then your loop controller is incorrect (0 To 3 = 3
iterations) and the loop should either be 0 To TicketOrder.TicketQty - 1 or
it should be 1 To TicketOrder.TicketQty.
 
S

Sumit

Hi all,
I would like to know all about the property EnableView state
in .Net. I also want to know about the Session creation in the asp.net.
 
C

CMM

Do a google search. Get a good book.
I recommend the ASP.NET Core Reference Book from Microsoft.
 
L

labelle

A friend told me the reason why is because i need to write the first
set of parameters to the database, then read them, then write them to
the second table.
I have absolutely no idea on how to do this, but I am guessing, I need
to declare my connection, give the command to read from the first
table...but i'm stumped?

How would I make the ticket orderID equal the total orderID?

tmpTicket.OrderID = ticketOrder.OrderID just won't work.


Dim cn As New SqlClient.SqlConnection("my connection")
Dim cmd As New SqlCommand("SELECT TOP 1 orderID FROM
dbo.TicketOrders ORDER BY orderID DESC")

Dim tmpTicket As OrderedTicket
Dim ticketParams As New ArrayList
Dim i As Integer = 0
For i = 0 To TicketOrder.TicketQty
ticketParams.Add((New SqlParameter("@orderID",
tmpTicket.OrderID)))
ticketParams.Add((New SqlParameter("@ticketID",
tmpTicket.TicketID)))
RunStoredProc("dbo.AddTicket", ticketParams)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top