Update\Insert In SQLLite

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

  1. ceaser

    ceaser Active Member Licensed User

    Help Please

    When entering coordinates via the keyboard (not imported), I have one button that says "Save". How do I go about letting the program know that it is a new point entered and not an updated one. I thought of doing first an "Update" and if that fails then do an "Insert".

    What happens if I first try an "Update", what returns if this "Update" fails, so that the program knows that it is a new point entered??:sign0085:

    Thanks
    Michael
     
  2. ceaser

    ceaser Active Member Licensed User

    OK I have figured it out::sign0060::cool:

    ErrorLabel (DupPoints)
    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=0 Then Goto DupPoints
    Return
    Else
    Msgbox ("Enter A Valid Point Name", "Point Name", cMsgboxOK, cMsgboxExclamation)
    PntName.Focus
    Return
    End If

    DupPoints:
    'The name does not exist so add the new data
    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


    A will be "1" be the point exists in which case I update the data, else if A is "0" then the point does not exists and I insert a new field.

    Thanks
    Michael
     
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