Quantcast
Viewing all articles
Browse latest Browse all 15785

VS 2019 Getting Last added row ID in SQLite

Hello All,

I am using following code to insert a row in SQLite database.

Wondering if it is possible to extract to ID, any suggestions will be most welcome.

thanks



Code:

  Public Sub WriteData()

        Try

         
            Dim myTablename As String = clsConst.tblProjectSpace

            Using myConn As New SQLiteConnection(myDatasource)

                myConn.Open()

                Using myCmd As New SQLiteCommand

                    Dim myQuery As String = String.Empty
                    myQuery = "INSERT INTO " & myTablename &
                                    "(" &
                                        clsConst.ProjNo & "," &
                                        clsConst.BldgNo & "," &
                                        clsConst.Phase & "," &
                                        clsConst.Scope & "," &
                                        clsConst.Filename & "," &
                                        clsConst.StartDate & "," &
                                        clsConst.EndDate & "," &
                                        clsConst.CreatedBy & "," &
                                        clsConst.CreatedOn &
                                    ")" &
                            "VALUES (" &
                                        "'" & Project & "', " &
                                        "'" & Building & "', " &
                                        "'" & Phase & "', " &
                                        "'" & Scope & "', " &
                                        "'" & Filename & "', " &
                                        "'" & StartDate & "', " &
                                        "'" & EndDate & "', " &
                                        "'" & CreatedBy & "', " &
                                        "'" & CreatedOn & "'" &
                                    ")"

                    myCmd.Connection = myConn
                    myCmd.CommandText = myQuery
                    myCmd.ExecuteNonQuery()


                ' Sample code for Extracting Last Inserted rowID by a user // this is not working
                    Dim myQuery2 As String = "select last_insert_rowid()"
                    myCmd.CommandText = myQuery2
                    Mycmd.ExecuteNonQuery

                    MessageBox.Show("Record successfully added !!")


                    Dim myPID As Integer = PID

                End Using

            End Using


        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub


Viewing all articles
Browse latest Browse all 15785

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>