Thursday, March 22, 2012

(GUID problem) What is wrong with this code ?

Hi, just learning SQL2000.
I have this code:
mSQL = "UPDATE Contactpersonen SET Naam=? WHERE ContactpersoonID=?"
Command = New SqlClient.SqlCommand(mSQL, C_CP)
Command.Parameters.Add("Naam", txtNaam.Text)
Command.Parameters.Add("CPID", SqlDbType.UniqueIdentifier).Value = m_CP_ID

where m_CP_ID is defined as a GUID in:
Public Property m_CP_ID() As Guid
Get
If Not viewstate("m_CP_ID") Is Nothing Then
Return viewstate("m_CP_ID")
End If
'Return 0
End Get
Set(ByVal Value As Guid)
viewstate("m_CP_ID") = Value
End Set
End Property

When running the app I got this error:
Server Error in '/4D' Application.
------------------------

Line 1: Incorrect syntax near 'Naam'. Line 1: Incorrect syntax near '?'.(points to mSQL above)
I know it has something to do with the GUID, but I cannot guess what.
Help is appreciated, Ger.


Try this:
mSQL = "UPDATE Contactpersonen SETNaam=@.Naam WHEREContactpersoonID=@.CPID"
Command = New SqlClient.SqlCommand(mSQL, C_CP)
Command.Parameters.Add("@.Naam", txtNaam.Text)
Command.Parameters.Add("@.CPID", SqlDbType.UniqueIdentifier).Value = m_CP_ID
|||Hey SonuKapoor, that works !!!!!!
Thanks a lot, every day I learn more and more... thanks to guys as you,
regards from the North Sea,
Ger.

No comments:

Post a Comment