PDA

View Full Version : سوال: مشکل backgroundWorker با sqlite و یا بانک اطلاعاتی



mr.siahatgar
سه شنبه 05 شهریور 1398, 11:32 صبح
سلام من یه برنامه نوشتم که یک سری اطلاعات که در تکس باکس ها هست وارد جدول sqlite میکنه در حالت عادی مشکلی ندارم و ازلاعات وارد میشه
اما وقتی در backgroundWorker کدها را قرار میدم عملیات بدون خطا انجام میشه ولی جدولم خالی میمونه و اطلاعات وارد نمیشه . تعجب من اینه که در کدها تکس باکس ها پر میشه ولی اینزرت به جدول نمیشه کسی میدونه مشکل چیه



private void BG_DoWork(object sender, DoWorkEventArgs e)
{

//33

if (BG.CancellationPending)
{
e.Cancel = true;
return;


}




SQLiteConnection con = new SQLiteConnection("Data Source=amar.db;version=3");
string sql = "insert into amarshamsi(stationum,station,milady,shamsi,yearmil ady,monthmilady,daymilady,time,yearshamsi,monthsha msi,dayshamsi,VISIBILITY,total,direction,speed,dry ,dewpoint,press,qff,rain,peresent,past,maxtemp,min temp,groundmin,sss,evaporate,f24f24f24f24,r24r24r2 4r24,wetblub,rh,dd,ff,ttt1,ttt2,ttt3,ttt4,ttt5,ttt 6,rh3,rh9,rh15,dayrain,dgusty,fgusty,fasl,fiftsss, grop1,grop2,grop3,grop4,grop5)values(@stationum,@s tation,@milady,@shamsi,@yearmilady,@monthmilady,@d aymilady,@time,@yearshamsi,@monthshamsi,@dayshamsi ,@VISIBILITY,@total,@direction,@speed,@dry,@dewpoi nt,@press,@qff,@rain,@peresent,@past,@maxtemp,@min temp,@groundmin,@sss,@evaporate,@f24f24f24f24,@r24 r24r24r24,@wetblub,@rh,@dd,@ff,@ttt1,@ttt2,@ttt3,@ ttt4,@ttt5,@ttt6,@rh3,@rh9,@rh15,@dayrain,@dgusty, @fgusty,@fasl,@fiftsss,@grop1,@grop2,@grop3,@grop4 ,@grop5)";
SQLiteCommand cmd = new SQLiteCommand(sql, con);
cmd.Parameters.AddWithValue("@stationum", textBox87.Text);
cmd.Parameters.AddWithValue("@station", textBox2.Text);
cmd.Parameters.AddWithValue("@milady", textBox7.Text);
cmd.Parameters.AddWithValue("@shamsi", textBox11.Text);
cmd.Parameters.AddWithValue("@yearmilady", textBox3.Text);
cmd.Parameters.AddWithValue("@monthmilady", textBox4.Text);
cmd.Parameters.AddWithValue("@daymilady", textBox5.Text);
cmd.Parameters.AddWithValue("@time", textBox6.Text);
cmd.Parameters.AddWithValue("@yearshamsi", textBox8.Text);
cmd.Parameters.AddWithValue("@monthshamsi", textBox9.Text);
cmd.Parameters.AddWithValue("@dayshamsi", textBox10.Text);
cmd.Parameters.AddWithValue("@VISIBILITY", textBox12.Text);
cmd.Parameters.AddWithValue("@total", textBox13.Text);
cmd.Parameters.AddWithValue("@direction", textBox14.Text);
cmd.Parameters.AddWithValue("@speed", textBox15.Text);
cmd.Parameters.AddWithValue("@dry", textBox16.Text);
cmd.Parameters.AddWithValue("@dewpoint", textBox17.Text);
cmd.Parameters.AddWithValue("@press", textBox18.Text);
cmd.Parameters.AddWithValue("@qff", textBox19.Text);
cmd.Parameters.AddWithValue("@rain", textBox22.Text);
cmd.Parameters.AddWithValue("@peresent", textBox24.Text);
cmd.Parameters.AddWithValue("@past", textBox25.Text);
cmd.Parameters.AddWithValue("@maxtemp", textBox31.Text);
cmd.Parameters.AddWithValue("@mintemp", textBox32.Text);
cmd.Parameters.AddWithValue("@groundmin", textBox33.Text);
cmd.Parameters.AddWithValue("@sss", textBox36.Text);
cmd.Parameters.AddWithValue("@evaporate", textBox35.Text);
cmd.Parameters.AddWithValue("@f24f24f24f24", textBox37.Text);
cmd.Parameters.AddWithValue("@r24r24r24r24", textBox38.Text);
cmd.Parameters.AddWithValue("@wetblub", textBox39.Text);
cmd.Parameters.AddWithValue("@rh", textBox40.Text);
cmd.Parameters.AddWithValue("@dd", textBox41.Text);
cmd.Parameters.AddWithValue("@ff", textBox42.Text);
cmd.Parameters.AddWithValue("@ttt1", textBox43.Text);
cmd.Parameters.AddWithValue("@ttt2", textBox44.Text);
cmd.Parameters.AddWithValue("@ttt3", textBox45.Text);
cmd.Parameters.AddWithValue("@ttt4", textBox46.Text);
cmd.Parameters.AddWithValue("@ttt5", textBox47.Text);
cmd.Parameters.AddWithValue("@ttt6", textBox48.Text);
cmd.Parameters.AddWithValue("@rh3", textBox80.Text);
cmd.Parameters.AddWithValue("@rh9", textBox81.Text);
cmd.Parameters.AddWithValue("@rh15", textBox82.Text);
cmd.Parameters.AddWithValue("@dayrain", textBox79.Text);
cmd.Parameters.AddWithValue("@dgusty", textBox83.Text);
cmd.Parameters.AddWithValue("@fgusty", textBox84.Text);
cmd.Parameters.AddWithValue("@fasl", textBox75.Text);
cmd.Parameters.AddWithValue("@fiftsss", textBox34.Text);
cmd.Parameters.AddWithValue("@grop1", "");
cmd.Parameters.AddWithValue("@grop2", "");
cmd.Parameters.AddWithValue("@grop3", "");
cmd.Parameters.AddWithValue("@grop4", "");
cmd.Parameters.AddWithValue("@grop5", "");

con.Open();
cmd.ExecuteNonQuery();
con.Close();

//progressBar2.Value += 1;

}
catch { }

}



}

محمد رضا فاتحی
سه شنبه 05 شهریور 1398, 15:35 عصر
شما قسمت Catch کدت رو به این صورت تغییر بده ببین خطایی نمایش میده یا نه

catch (Exception ex)
{
MessageBox.show(ex.ToString());
}

danialafshari
سه شنبه 05 شهریور 1398, 20:26 عصر
با سلام
اول اینکه این کد عمل نمیده چون از object توش استفاده کردید مگر اینکه CheckForIllegalCrossThreadCalls برابر false باشه
دوم اینکه مطمئن هستید که این کد اجرا میشه؟ Breakpoint گذاشتید؟ آخه جایی نمیبینم Run کرده باشید
BG.RunWorkerAsync();

mr.siahatgar
چهارشنبه 06 شهریور 1398, 14:02 عصر
بله همه این کارها را کردم
نکته جالب اینکه همه رو بردم توی یک فرم دیگه درست شد . من که جریانش نفهمیدم ولی درست شد