SQLLite

Discussion in 'Questions (Windows Mobile)' started by ceaser, Oct 12, 2008.

  1. ceaser

    ceaser Active Member Licensed User

    Hi All:sign0085:

    I get to grips with B4PPC - with everything, except SQLLte:sign0148: I have the following code where I can store a coordinate or update a coordinate::sign0148:

    Sub SaveCoord_Click
    Dim a

    ErrorLabel (NoPoint)
    If PntName.Text<>"" Then
    If CFile=0 Then
    text="update LCoords Set YCoord = '"
    Else If CFile=1 Then
    text="update LCoords Set YCoord = '"
    Else
    text="update LCoords Set YCoord = '"
    End If
    Text=Text & YCoord.Text & "'," & "XCoord = '" & XCoord.Text & "'," & "ZCoord = '" & ZCoord.Text
    Text=Text & "'," & "Description = '" & Descrip.Text & "'"
    Text=Text & " where PntName = '" & PntName.Text &"'"
    cmd.CommandText=text
    A=cmd.ExecuteNonQuery
    *** If A=1 Then
    'Point exits
    Msgbox ("Point Exists - Override?", "Point Exits", cMsgboxYesNo, cMsgboxQuestion)
    End If **
    If A=0 Then Goto NoPoint
    ShowCoords(1,CFile)
    Return
    Else
    Msgbox ("Enter A Valid Point Name", "Point Name", cMsgboxOK, cMsgboxExclamation)
    PntName.Focus
    Return
    End If

    NoPoint:
    'The point does not exist so add the new point
    If CFile=0 Then
    text="insert into LCoords (PntName,YCoord,XCoord,ZCoord,Description) values ('"
    Else If CFile=1 Then
    text="insert into GCoords (PntName,YCoord,XCoord,ZCoord,Description) values ('"
    Else
    text="insert into SCoords (PntName,YCoord,XCoord,ZCoord,Description) values ('"
    End If
    text=text & PntName.Text & "','" & YCoord.Text & "','" & XCoord.Text & "','" & ZCoord.Text & "','" & Descrip.Text & "')"
    cmd.CommandText=text
    cmd.ExecuteNonQuery
    ShowCoords(1,CFile)
    End Sub

    Looking at the line codes marked with an astrixs, is where when A=1, the point exists and the new values get updated. How can I "Rollback" that command or have another command to check if the point exists before the values get changed in the database?:confused:

    Thanks
    Michael
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I really recommend you to try to use parameterized queries.
    Your code will be much simpler.

    Can't you first run a SELECT query and only then run the UPDATE query if needed?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice