Problems with parameters.

G

Guest

Hi,

I am inserting new rows into two datatables (Client and Booking). When the submit button is clicked, i am using the dataAdapter.UPdate method to propogate the inserts into my database.

The Client (Parent table) insert works ok and the values can be seen in my database.
The automatically genereated ClientID (@Identity) is then returned and inputed back into my datatable with the correct value.

I now tried to write code below this Client insert to update my bookings table. (still under the same onclick event of my submit button)
This table contains:
BookingNo (Autonumber)
ClientID (Should contain the same value as the parent client autonumber)
Invoice number

I tried the following code to perform my insert into the booking table after the client table had been updated:

Dim cmdInsBooking As New SqlCommand("InsBookingAndSelIdentity", cn)
'declare a variable that wil hold the newly generated clientID so it can b inputted into
'dtBooking.
Dim ClientIdentity As Integer
'this will return the newly generated ClientID from the Client datatable so that it can be inserted into the booking table
ClientIdentity = dsFullBooking.Tables("dtClient").Rows(0)("ClientID")

daClient.InsertCommand = cmdInsBooking
daClient.InsertCommand.CommandType = CommandType.StoredProcedure


daClient.InsertCommand.Parameters.Add("@ClientID", SqlDbType.Int, 4, ClientIdentity)
daClient.InsertCommand.Parameters.Add("@InvoiceNo", SqlDbType.Char, 50, "InvoiceNo")

Dim myBookingIdentity As SqlParameter = daClient.InsertCommand.Parameters.Add
("@Identity", SqlDbType.Int, 0, "BookingNo")
myBookingIdentity.Direction = ParameterDirection.Output

Try
cn.Open()
daClient.Update(dsFullBooking.Tables("dtBooking"))
Catch x As Exception
MsgBox(x.Message)
Finally
cn.Close()
End Try


When i try and run this, i get a message stating:
Procedure 'InsBookingAndSelIdentity' expects parameter '@ClientID', which is not supplied.

Can anyone tell me what i may be doin wrong.
Iv been stuck for ages so any help would be excellent.
 

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