Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL方法需要很长时间_C#_Sqlite - Fatal编程技术网

C# SQL方法需要很长时间

C# SQL方法需要很长时间,c#,sqlite,C#,Sqlite,我将SQLite与C#一起使用 我使用以下方法循环浏览电视节目及其剧集的列表,并将其插入数据库。它最终进入大约1200行,需要2分28秒。这感觉有点慢,所以我想让人们看看我的方法,看看我是否在做一些愚蠢的事情(我对这有点陌生) public void InsertAllEpisodes(列表显示列表) { 使用(SQLiteConnection dbconnection=newsqliteconnection(connectionString)) { 字符串编号; 弦幕数; string ins

我将SQLite与C#一起使用

我使用以下方法循环浏览电视节目及其剧集的列表,并将其插入数据库。它最终进入大约1200行,需要2分28秒。这感觉有点慢,所以我想让人们看看我的方法,看看我是否在做一些愚蠢的事情(我对这有点陌生)

public void InsertAllEpisodes(列表显示列表)
{
使用(SQLiteConnection dbconnection=newsqliteconnection(connectionString))
{
字符串编号;
弦幕数;
string insertShowSQL=@“插入AllEpisodes(键、ShowName、ShowId、eposodeName、季节性插曲)值(@Key、@ShowName、@ShowId、@eposodeName、@seasure插曲)”;
foreach(在showList中显示变量)
{
foreach(show.Spices中的var片段)
{
如果(插曲编号!=0)
{
string=“default”;
如果((session.sessionnumber!=0)和&(session.sessionnumber.ToString().Length==1)){sessionnumber=“0”+session.sessionNumber.ToString();}
else{seasenNumber=eposion.seasenNumber.ToString();}
如果(eposion.eposodenumber.ToString().Length==1){eposodenumber=“0”+eposion.eposodenumber.ToString();}
else{epiodenumber=eposion.epiodenumber.ToString();}
季节情节=季节编号+情节编号;
SQLiteCommand=newsqlitecommand(insertShowSQL,dbconnection);
command.Parameters.AddWithValue(“Key”,show.Id+sessional);
command.Parameters.AddWithValue(“ShowName”,show.Name);
command.Parameters.AddWithValue(“ShowId”,show.Id);
command.Parameters.AddWithValue(“eposodeName”,插曲.Title);
command.Parameters.AddWithValue(“季节情节”,季节情节);
dbconnection.Open();
尝试
{
command.ExecuteScalar();
}
catch(SQLiteException-ex)
{
if(ex.ResultCode!=SQLiteErrorCode.Constraint)
{
File.AppendAllText(programDataPath+“SQLErrors.txt”,例如Message+“\n”);
}
}
dbconnection.Close();
}
}
}
}
}

我阅读并使用了
sqlComm=new-SQLiteCommand(“begin”,dbconnection)
sqlComm=new-SQLiteCommand(“end”,dbconnection)
,并在不到1秒的时间内将其插入

public void InsertAllEpisodes(List<TVDBSharp.Models.Show> showList)
    {

        using (SQLiteConnection dbconnection = new SQLiteConnection(connectionString))
        {

            dbconnection.Open();
            string seasonNumber;
            string episodeNumber;
            string insertShowSQL = @"INSERT INTO AllEpisodes (Key, ShowName, ShowId, EpisodeName, SeasonEpisode) VALUES (@Key, @ShowName, @ShowId, @EpisodeName, @SeasonEpisode)";
            SQLiteCommand sqlComm;
            sqlComm = new SQLiteCommand("begin", dbconnection);
            sqlComm.ExecuteNonQuery();
            foreach (var show in showList)
            {
                foreach (var episode in show.Episodes)
                {
                    if (episode.SeasonNumber != 0)
                    {
                        string seasonEpisode = "default";
                        if ((episode.SeasonNumber != 0) && (episode.SeasonNumber.ToString().Length == 1)) { seasonNumber = "0" + episode.SeasonNumber.ToString(); }
                        else { seasonNumber = episode.SeasonNumber.ToString(); }
                        if (episode.EpisodeNumber.ToString().Length == 1) { episodeNumber = "0" + episode.EpisodeNumber.ToString(); }
                        else { episodeNumber = episode.EpisodeNumber.ToString(); }
                        seasonEpisode = seasonNumber + episodeNumber;
                        sqlComm = new SQLiteCommand(insertShowSQL, dbconnection);
                        sqlComm.Parameters.AddWithValue("Key", show.Id + seasonEpisode);
                        sqlComm.Parameters.AddWithValue("ShowName", show.Name);
                        sqlComm.Parameters.AddWithValue("ShowId", show.Id);
                        sqlComm.Parameters.AddWithValue("EpisodeName", episode.Title);
                        sqlComm.Parameters.AddWithValue("SeasonEpisode", seasonEpisode);
                        try
                        {
                            sqlComm.ExecuteScalar();
                        }
                        catch (SQLiteException ex)
                        {
                            if (ex.ResultCode != SQLiteErrorCode.Constraint)
                            {
                                File.AppendAllText(programDataPath + "SQLErrors.txt", ex.Message + "\n");
                            }
                        }

                    }
                }

            }
            sqlComm = new SQLiteCommand("end", dbconnection);
            sqlComm.ExecuteNonQuery();
            dbconnection.Close();

        }

    }
public void InsertAllEpisodes(列表显示列表)
{
使用(SQLiteConnection dbconnection=newsqliteconnection(connectionString))
{
dbconnection.Open();
字符串编号;
弦幕数;
string insertShowSQL=@“插入AllEpisodes(键、ShowName、ShowId、eposodeName、季节性插曲)值(@Key、@ShowName、@ShowId、@eposodeName、@seasure插曲)”;
sqlitecommandsqlcomm;
sqlComm=newsqlitecommand(“begin”,dbconnection);
sqlComm.ExecuteNonQuery();
foreach(在showList中显示变量)
{
foreach(show.Spices中的var片段)
{
如果(插曲编号!=0)
{
string=“default”;
如果((session.sessionnumber!=0)和&(session.sessionnumber.ToString().Length==1)){sessionnumber=“0”+session.sessionNumber.ToString();}
else{seasenNumber=eposion.seasenNumber.ToString();}
如果(eposion.eposodenumber.ToString().Length==1){eposodenumber=“0”+eposion.eposodenumber.ToString();}
else{epiodenumber=eposion.epiodenumber.ToString();}
季节情节=季节编号+情节编号;
sqlComm=newsqlitecommand(insertShowSQL,dbconnection);
sqlComm.Parameters.AddWithValue(“Key”,show.Id+session);
sqlComm.Parameters.AddWithValue(“ShowName”,show.Name);
sqlComm.Parameters.AddWithValue(“ShowId”,show.Id);
sqlComm.Parameters.AddWithValue(“eposodeName”,插曲.Title);
sqlComm.Parameters.AddWithValue(“季节性插曲”,季节性插曲);
尝试
{
sqlComm.ExecuteScalar();
}
catch(SQLiteException-ex)
{
if(ex.ResultCode!=SQLiteErrorCode.Constraint)
{
File.AppendAllText(programDataPath+“SQLErrors.txt”,例如Message+“\n”);
}
}
}
}
}
sqlComm=新的SQLiteCommand(“end”,dbconnection);
sqlComm.ExecuteNonQuery();
dbconnection.Close();
}
}

我阅读并使用了
sqlComm=new-SQLiteCommand(“begin”,dbconnection)
sqlComm=new-SQLiteCommand(“end”,dbconnection)
,并在不到1秒的时间内将其插入

public void InsertAllEpisodes(List<TVDBSharp.Models.Show> showList)
    {

        using (SQLiteConnection dbconnection = new SQLiteConnection(connectionString))
        {

            dbconnection.Open();
            string seasonNumber;
            string episodeNumber;
            string insertShowSQL = @"INSERT INTO AllEpisodes (Key, ShowName, ShowId, EpisodeName, SeasonEpisode) VALUES (@Key, @ShowName, @ShowId, @EpisodeName, @SeasonEpisode)";
            SQLiteCommand sqlComm;
            sqlComm = new SQLiteCommand("begin", dbconnection);
            sqlComm.ExecuteNonQuery();
            foreach (var show in showList)
            {
                foreach (var episode in show.Episodes)
                {
                    if (episode.SeasonNumber != 0)
                    {
                        string seasonEpisode = "default";
                        if ((episode.SeasonNumber != 0) && (episode.SeasonNumber.ToString().Length == 1)) { seasonNumber = "0" + episode.SeasonNumber.ToString(); }
                        else { seasonNumber = episode.SeasonNumber.ToString(); }
                        if (episode.EpisodeNumber.ToString().Length == 1) { episodeNumber = "0" + episode.EpisodeNumber.ToString(); }
                        else { episodeNumber = episode.EpisodeNumber.ToString(); }
                        seasonEpisode = seasonNumber + episodeNumber;
                        sqlComm = new SQLiteCommand(insertShowSQL, dbconnection);
                        sqlComm.Parameters.AddWithValue("Key", show.Id + seasonEpisode);
                        sqlComm.Parameters.AddWithValue("ShowName", show.Name);
                        sqlComm.Parameters.AddWithValue("ShowId", show.Id);
                        sqlComm.Parameters.AddWithValue("EpisodeName", episode.Title);
                        sqlComm.Parameters.AddWithValue("SeasonEpisode", seasonEpisode);
                        try
                        {
                            sqlComm.ExecuteScalar();
                        }
                        catch (SQLiteException ex)
                        {
                            if (ex.ResultCode != SQLiteErrorCode.Constraint)
                            {
                                File.AppendAllText(programDataPath + "SQLErrors.txt", ex.Message + "\n");
                            }
                        }

                    }
                }

            }
            sqlComm = new SQLiteCommand("end", dbconnection);
            sqlComm.ExecuteNonQuery();
            dbconnection.Close();

        }

    }
public void InsertAllEpisodes(列表显示列表)
{
使用(SQLiteConnection dbconnection=newsqliteconnection(connectionString))
{
dbconnection.Open();
字符串编号;
弦幕数;
串插入器