SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Phoenix
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question textbox content stored as database integer?

    In an Access table I have a field with type Number (Integer) and need to store an ASP.NET textbox value in it. I get a syntax error in the INSERT command when I use:

    objCmd.Parameters.Add("@Level", FormatNumber(txtLevel.Text)) or any other conversion function I have tried

    yet in another page the command

    objCmd.Parameters.Add("@CostPerPerson", FormatCurrency(txtCostPerPerson.Text))

    works fine.

    How do I store a numeric text value as a database numeric value?

  2. #2
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Jersey
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this

    Code:
    objCmd.Parameters.Add("@Level", (int)txtLevel.Text)
    alternatively you could convert it before you add it

    Code:
    string strLevel;
    strLevel = (int) txtLevel.Text;
    
    ...
    
    objCmd.Parameters.Add("@Level", strLevel)
    Matt Daly

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Phoenix
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Matt, but that does not work.

    I cut out everything except the Level parameter and here is what my UPDATE looks like now:

    strCmd = "Insert Into tblSponsors (Level) Values (@Level)"
    Dim objCmd As New OleDbCommand(strCmd, objConn)
    objCmd.Parameters.Add("@Level", int(txtLevel.Text))
    objConn.Open()
    objCmd.ExecuteNonQuery()
    objConn.Close()

  4. #4
    SitePoint Addict danfran's Avatar
    Join Date
    Jan 2005
    Location
    New York City
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it work when you put in a literal value?

    objCmd.Parameters.Add("@Level", 123)
    or..
    objCmd.Parameters.Add("@Level", "123")

    Dan

  5. #5
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Phoenix
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, not with either, Dan

  6. #6
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Phoenix
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I found the problem and have solved it. I had to change the field name "Level" to something else. Apparently that is a reserved word.

    Thanks to all who tried to help!

    Dave


Bookmarks

Posting Permissions

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