Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Vb.Net Update Command Problem

Vb.Net Update Command Problem

Vb.Net Update Command Problem

The Physician table has PhysicianPk as Int(11). I'm getting an System.InvalidCastException: Conversion from string "physicianPK" to type Integer is not invalid. Why does it think PhysicianPk is a string? I also tried all of the Int16,24,32,64 types.

Here is the code


Dim adapter As MySqlDataAdapter = New MySqlDataAdapter()

    ' Create the SelectCommand. 
    Dim command As MySqlCommand = New MySqlCommand( _
        "SELECT * FROM Physician", connection)

    ' Create the UpdateCommand.
    command = New MySqlCommand( _
        "UPDATE Physician SET LastName = @LastName, FirstName = @FirstName " & _
        "WHERE PhysicianPK = @oldPhysicianPK", connection)

      ' Add the parameters for the UpdateCommand.
      command.Parameters.Add("@PhysicianPK", MySqlDbType.Int24, "PhysicianPK")
      command.Parameters.Add("@LastName", MySqlDbType.VarChar, 20, "LastName")
      command.Parameters.Add("@FirstName", MySqlDbType.VarChar, 15, "FirstName")
      Dim parameter As MySqlParameter = command.Parameters.Add( _
          "@oldPhysicianPK", MySqlDbType.Int24, "PhysicianPK")
      parameter.SourceVersion = DataRowVersion.Original
    Catch ex As Exception
    End Try 

Sylvania/Toledo Ohio

RE: Vb.Net Update Command Problem


Quote (Auguy)

Why does it think PhysicianPk is a string?
This is not MySQL related problem. In most of the languages character literals enclosed in double quotes are considered string.

In case PhysicianPK is a variable containing an integer value, just remove the double quotes :

CODE --> )

command.Parameters.Add("@PhysicianPK", MySqlDbType.Int24, PhysicianPK) 

For further assistance in this problem, better post in a forum dedicated to Visual Basic.


RE: Vb.Net Update Command Problem


better post in a forum dedicated to Visual Basic.

Which is forum796: Visual Basic(Microsoft) -VB.NET


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Vb.Net Update Command Problem

Thanks, I will do that.

Sylvania/Toledo Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close