Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vb.Net Update Command Problem

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
0
36
US
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
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)

    Try
      ' 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
      MessageBox.Show(ex.ToString)
    End Try


Auguy
Sylvania/Toledo Ohio
 
Hi

Auguy said:
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.

Feherke.
feherke.ga
 
better post in a forum dedicated to Visual Basic.

Which is forum796

Chris.

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

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top