Click here to Skip to main content
15,041,548 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.

Thanks,

Josh

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

SQLconnect.ConnectionString = "Data Source=" & strFile
SQLconnect.Open()

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

    'SeriesId, EpisodeName, SeasonNumber, EpisodeNumber, Overview, Director, Rating, PosterUrl, Writers
    Try
        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 + "|"
        Next
        cmd.Parameters.Add("@Writers", Data.DbType.String).Value = writers
        Dim inte As Integer = 0

        cmd.ExecuteNonQuery()


    Catch ex As Exception
        Debug.WriteLine(ex.Message.ToString)
    End Try
Next

Try

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

    End Try
Catch ex As Exception
    SQLconnect.Close()
End Try
Posted

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.
   

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