C# 以10秒的间隔写入数据库

C# 以10秒的间隔写入数据库,c#,sql-server,database,C#,Sql Server,Database,我正在使用一个情感分析API,它分析视频,然后将读取的情感存储到数据库中。我写了下面的代码,试图让它在每10秒的视频中存储情感。它不会将任何内容写入数据库,但是,当我删除 如果(具有.getFrameTimeStamp()%10000==0){ 部分,它按正常每秒写入,这是我不想要的 has.getFrameTimeStamp()=视频的特定秒数 if (has.getFrameTimeStamp() % 10000 == 0) { using (SqlConnection conn = new

我正在使用一个情感分析API,它分析视频,然后将读取的情感存储到数据库中。我写了下面的代码,试图让它在每10秒的视频中存储情感。它不会将任何内容写入数据库,但是,当我删除

如果(具有.getFrameTimeStamp()%10000==0){

部分,它按正常每秒写入,这是我不想要的

has.getFrameTimeStamp()=视频的特定秒数

if (has.getFrameTimeStamp() % 10000 == 0) {
using (SqlConnection conn = new SqlConnection(@"<file path>")) {
 conn.Open();

using (SqlCommand cmd1 = new SqlCommand("INSERT INTO TBL_VIDEO(TIMESTAMP,JOY_SCORE,SURPRISE_SCORE,ANGER_SCORE,FEAR_SCORE,SADNESS_SCORE,DISGUST_SCORE) VALUES('" + has.getFrameTimeStamp().ToString() + "','" + people.get(i).impression.emotion_response.joy_score.ToString() + "','" + people.get(i).impression.emotion_response.surprise_score.ToString() + "','" + people.get(i).impression.emotion_response.anger_score.ToString() + "','" + people.get(i).impression.emotion_response.fear_score.ToString() + "','" + people.get(i).impression.emotion_response.sadness_score.ToString() + "','" + people.get(i).impression.emotion_response.disgust_score.ToString() + "')", conn)) {

using (SqlDataReader dr = cmd1.ExecuteReader()) {

                                    }
                                }
                            }
                        }
if(has.getFrameTimeStamp()%10000==0){
正在使用(SqlConnection conn=newsqlconnection(@“”){
conn.Open();
使用(SqlCommand cmd1=new SqlCommand(“插入TBL_视频(时间戳、喜悦_分数、惊喜_分数、愤怒_分数、恐惧_分数、悲伤_分数、厌恶_分数)”值(“+has.getFrameTimeStamp().ToString()+”、“+people.get(i).impression.Mootion_response.JOY_分数.ToString()+”、“+people.get(i).impression.Mootion_response.ToString()”)“+people.get(i)impression.emotion(i)response.anger(i)score.ToString()+”,“+people.get(i)impression.emotion(i)response.恐惧(i)score.ToString()+”,“+people.get(i)impression.emotion(i)response.悲伤(i)score.ToString()+”,“+people.get(i)impression.emotion(i)response.ToString(i)response.ToString(i)response.ToString(厌恶(i)score.ToString()+”,康{
使用(SqlDataReader dr=cmd1.ExecuteReader()){
}
}
}
}

任何帮助/建议都将不胜感激。谢谢!

你的基本意思是,每166分钟更新一次我的数据库

如果你想要10秒钟,你需要做10秒钟的练习

提示,整理好你的代码,你会绊倒并伤害自己:)


在计算中,模运算找到除法后的余数 一个数乘以另一个数(有时称为模数)

余数运算符(%)在除以余数后计算余数 第一个操作数乘以第二个操作数。所有数值类型都有预定义的 余数运算符


has.getFrameTimeStamp()
seconds,minutes,datetime,smileyfaces/hour?的格式是什么?@TheGeneral seconds。所以你想让它每166.6667分钟更新一次吗?你应该使用参数化查询,而不是字符串concats。如果你想让它更简单,可以使用dapper之类的工具
if (has.getFrameTimeStamp() % 10 == 0)