sql server - Trigger will not fire at all after bulkcopy -


i want update inserted records after using bulkcopy insert them database. want have written trigger update me after insert. trigger works fine if insert records 1 after other refuses work after bulkcopy insert.

i have added fire trigger (sqlbulkcopyoptions.firetriggers & sqlbulkcopyoptions.checkconstraints) connection still not work.

this trigger wrote:

create trigger [dbo].[trigger_assessment] on [dbo].[assessment] after insert  begin     set nocount on      declare @a int     declare @b int      select @b = exam_score, @a = ca      inserted      update assessment      set final_ca = ca*0.3, final_exam = exam_score * 0.7,         f_score = ((ca * 0.3) + (exam_score * 0.7))      exam_score = @b , ca = @a end 

and bulk copy:

     dim koneksi_excel new      system.data.oledb.oledbconnection("provider=microsoft.ace.oledb.12.0; data source='" & path1.text & " '; extended properties=""excel 12.0 xml;hdr=yes""")      koneksi_excel.open()     dim query_excel string = "select * [sheet1$]"      dim cmd oledbcommand = new oledbcommand(query_excel, koneksi_excel)      dim rd oledbdatareader      dim koneksi new sqlconnection()      if mysqlconnectionstring.state = connectionstate.closed         mysqlconnectionstring.open()     end if     using bulkcopy sqlbulkcopy = new sqlbulkcopy(configurationmanager.connectionstrings("schooldbconnectionstring").connectionstring.tostring, sqlbulkcopyoptions.firetriggers & sqlbulkcopyoptions.checkconstraints)          bulkcopy.destinationtablename = "dbo.assessment"          try              rd = cmd.executereader             bulkcopy.writetoserver(rd)             rd.close()             mysqlconnectionstring.close()             msgbox("data import succesful", msgboxstyle.information, "imports")             path.text = ""         catch ex exception             msgbox(ex.tostring)                     mysqlconnectionstring.close()         end try     end using 

i want assistance please, thank you

the inserted virtual table table, , can have more 1 row. if bulk insert (or update), table have more 1 row in it. need take account. can read more here: use inserted , deleted tables.


your corrected trigger be:

create trigger [dbo].[trigger_assessment] on [dbo].[assessment] after insert begin     set nocount on      update          assessment      set          final_ca=a.ca*0.3,         final_exam=a.exam_score*0.7,         f_score=((a.ca*0.3)+(a.exam_score*0.7))              assessment         inner join inserted on             i.ca=a.ca ,             i.exam_score=a.exam_score; end 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -