Results 1 to 3 of 3

Thread: [RESOLVED] ERROR: Parameter ?_1 has no default value. Visual Studio 2013

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    3

    Resolved [RESOLVED] ERROR: Parameter ?_1 has no default value. Visual Studio 2013

    Private Sub btnInsertRoom_Click(sender As Object, e As EventArgs) Handles btnInsertRoom.Click
    Dim oConnection As OleDbConnection = New OleDbConnection(CONNECTION_STRING)

    Try
    Debug.Print("Connection string: " & oConnection.ConnectionString)

    oConnection.Open()
    Dim oCommand As OleDbCommand = New OleDbCommand
    oCommand.Connection = oConnection

    Dim htData As Hashtable = New Hashtable
    htData("Room_number") = txtRoom_Number.Text
    htData("Type") = cbxType.Text
    htData("Price") = txtPrice.Text
    htData("Num_Beds") = txtNum_Beds.Text
    htData("Availability") = TxtAvailability.Text
    htData("Floor") = txtFloor.Text
    htData("Description") = txtDescription.Text

    oCommand.CommandText = "INSERT INTO room (room_number, type, price, num_beds, availability, floor, description) VALUES (?, ?, ?, ?, ?, ?, ?);"
    oCommand.Parameters.Add("room_number", OleDbType.VarChar, 255)
    oCommand.Parameters.Add("type", OleDbType.VarChar, 255)
    oCommand.Parameters.Add("price", OleDbType.Double, 8)
    oCommand.Parameters.Add("num_beds", OleDbType.Integer, 1)
    oCommand.Parameters.Add("availability", OleDbType.VarChar, 255)
    oCommand.Parameters.Add("floor", OleDbType.VarChar, 255)
    oCommand.Parameters.Add("description", OleDbType.VarChar, 255)

    oCommand.Parameters("room_number").Value = CStr(htData("room_number"))
    oCommand.Parameters("type").Value = CStr(htData("type"))
    oCommand.Parameters("price").Value = CDbl(htData("price"))
    oCommand.Parameters("num_beds").Value = CInt(htData("num_beds"))
    oCommand.Parameters("availability").Value = CStr(htData("availability"))
    oCommand.Parameters("floor").Value = CStr(htData("floor"))
    oCommand.Parameters("description").Value = CStr(htData("description"))

    oCommand.Prepare()

    Debug.Print("SQL: " & oCommand.CommandText)

    oCommand.ExecuteNonQuery()

    Debug.Print("The record was inserted.")

    Catch ex As Exception
    Debug.Print("ERROR: " & ex.Message)
    MsgBox("An error occurred. The record wasn't inserted.")
    Finally
    oConnection.Close()
    End Try
    End Sub

    I am getting the ERROR: Parameter ?_1 has no default value.
    and i have no idea what to do now.
    PLEASE HELP!

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,248

    Re: ERROR: Parameter ?_1 has no default value. Visual Studio 2013

    Check your parameters and make sure they all have values. My guess is that it's the first parameter - room_number - that is not being set. That is... CStr(htData("room_number")) is returning a null reference. Since there's no default value specified for that parameter, it doesn't know what to insert into the db.
    I always add to the reputation of those whose post are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: ERROR: Parameter ?_1 has no default value. Visual Studio 2013

    Quote Originally Posted by dolot View Post
    Check your parameters and make sure they all have values. My guess is that it's the first parameter - room_number - that is not being set. That is... CStr(htData("room_number")) is returning a null reference. Since there's no default value specified for that parameter, it doesn't know what to insert into the db.
    Thats what I would guess too. If CStr(htData("room_number")) is returning a null reference then he should be passing DBNull if thats what he intends to pass (probably not). As you said, he should add a watch to his values to make sure they're what he is expecting

    nickdim, you should not be converting items using CSTR(), CDBL(), CINT(), and as a healthy habit I would say when dealing with (storing or calculating) money you should always use Decimal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width