Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

I am trying to insert a tv episode into a database. I have tried everything but it will only add one item, the last episode. It is iterating correctly but it never adds more than just one item. What am I missing? I know it is something stupid but I have been staring at this for over an hour trying to fix it but no success. Database is already created, file exists and opens. Iterates correctly.... WHAT AM I MISSING??? Rrrrg.

Any ideas?

And if you have a second, I would love to do it with a transaction (that's where I started) but that, of course, didn't work either.



Dim strFile As String = DBFile
Dim SQLconnect As New SQLiteConnection()

SQLconnect.ConnectionString = "Data Source=" & strFile

For i As Integer = 0 To _TvSeries.Episodes.Length - 1

    'SeriesId, EpisodeName, SeasonNumber, EpisodeNumber, Overview, Director, Rating, PosterUrl, Writers
        Dim cmd As New SQLiteCommand("Insert or Replace Into " & _TvSeries.SeriesName.Replace(" ", "_") & " (SeriesId,EpisodeName,SeasonNumber,EpisodeNumber,Overview,Director,Rating,PosterUrl,Writers) VALUES (@SeriesId, @EpisodeName, @SeasonNumber, @EpisodeNumber, @Overview, @Director, @Rating, @PosterUrl, @Writers);", SQLconnect)
        '@SeriesId, EpisodeName, SeasonNumber, EpisodeNumber, Overview, Director, Rating, PosterUrl, Writers
        cmd.Parameters.Add("@SeriesId", Data.DbType.String).Value = _TvSeries.SeriesId
        cmd.Parameters.Add("@EpisodeName", Data.DbType.String).Value = _TvSeries.Episodes(i).EpisodeName
        cmd.Parameters.Add("@SeasonNumber", Data.DbType.String).Value = _TvSeries.Episodes(i).SeasonNumber
        cmd.Parameters.Add("@EpisodeNumber", Data.DbType.String).Value = _TvSeries.Episodes(i).EpisodeNumber
        cmd.Parameters.Add("@Overview", Data.DbType.String).Value = _TvSeries.Episodes(i).Overview
        cmd.Parameters.Add("@Director", Data.DbType.String).Value = _TvSeries.Episodes(i).Director
        cmd.Parameters.Add("@Rating", Data.DbType.String).Value = _TvSeries.Episodes(i).Rating
        cmd.Parameters.Add("@PosterUrl", Data.DbType.String).Value = _TvSeries.Episodes(i).PosterUrl

        Dim writers As String = ""
        For Each strwriters In _TvSeries.Episodes(i).Writers
            writers += strwriters + "|"
        cmd.Parameters.Add("@Writers", Data.DbType.String).Value = writers
        Dim inte As Integer = 0


    Catch ex As Exception
    End Try


        If Not SQLconnect Is Nothing Then SQLconnect.Dispose()
    Catch ex As Exception

    End Try
Catch ex As Exception
End Try

1 solution

Sigh.... Figured it out. Didn't put in an AUTOINCREMENTing primary key. I had a primary key, but it didn't autoincrement. So for you google users that find this, there you go.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900