so a code like that
do you think it will work??Code:con.Open() Dim thisTransaction As SqlTransaction thisTransaction = con.BeginTransaction() Try Dim paramar(3) As SqlParameter paramar(0) = New SqlParameter("@id", SqlDbType.Int, 4) paramar(0).Value = last_id + 1 paramar(1) = New SqlParameter("@caption", SqlDbType.NVarChar) paramar(1).Value = tbox_text_caption2.Text paramar(2) = New SqlParameter("@image", SqlDbType.NVarChar) paramar(2).Value = "~/photos/allesomades" & fname paramar(3) = New SqlParameter("@imerominia", SqlDbType.DateTime, 512) paramar(3).Value = Date.UtcNow.AddHours(3) ' paramar(2) = New sqlParameter("@data", sqlType.VarChar, Session("maxtextsize")) ' paramar(2).Value = tbox_text_data.Text Dim sqlda As New SqlDataAdapter() sqlda.SelectCommand = New SqlCommand() sqlda.SelectCommand.Transaction = thisTransaction sqlda.SelectCommand.Connection = con sqlda.SelectCommand.Parameters.Add(paramar(0)) sqlda.SelectCommand.Parameters.Add(paramar(1)) sqlda.SelectCommand.Parameters.Add(paramar(2)) sqlda.SelectCommand.Parameters.Add(paramar(3)) sqlda.SelectCommand.CommandText = "insert into eidiseis_sxolia_allon_omadon (text_id,text_caption,image,imerominia) values (@id,@caption,@image,@imerominia)" Dim ds As New DataSet() sqlda.Fill(ds) ds.Dispose() 'tbox_text_data.Text = "" Dim mycommandtab As New SqlCommand("create table alles_omades" & last_id + 1 & " (text_id int null,text_caption nvarchar(max) null,melos nvarchar(max) null,site nvarchar(max),titlos nvarchar(max) null,imerominia datetime null,quoted int null)", con) mycommandtab.Transaction = thisTransaction dr = mycommandtab.ExecuteReader() dr.Close() 'Catch ex As SqlException 'Response.Write("problima kai anairesi allagon:" & ex.Message.ToString) ' End Try Dim paramard(2) As SqlParameter paramard(0) = New SqlParameter("@id", SqlDbType.Int, 4) paramard(0).Value = 1 paramard(1) = New SqlParameter("@caption", SqlDbType.NVarChar) paramard(1).Value = tbox_text_caption3.Text paramard(2) = New SqlParameter("@imerominia", SqlDbType.DateTime, 512) paramard(2).Value = Date.UtcNow.AddHours(3) ' paramar(2) = New sqlParameter("@data", sqlType.VarChar, Session("maxtextsize")) ' paramar(2).Value = tbox_text_data.Text Dim sqldad As New SqlDataAdapter() sqldad.SelectCommand = New SqlCommand() sqldad.SelectCommand.Transaction = thisTransaction sqldad.SelectCommand.Connection = con sqldad.SelectCommand.Parameters.Add(paramard(0)) sqldad.SelectCommand.Parameters.Add(paramard(1)) sqldad.SelectCommand.Parameters.Add(paramard(2)) sqldad.SelectCommand.CommandText = "insert into alles_omades" & last_id + 1 & " (text_id,text_caption,imerominia,quoted) values (@id,@caption,@imerominia,0)" Dim dsd As New DataSet() sqldad.Fill(dsd) tbox_text_caption3.Text = "" dsd.Dispose() thisTransaction.Commit() Catch ex As Exception Session("lathos") = True Session("messagelathous") = "tis pire piso" thisTransaction.Rollback() Finally con.Close() End Try
another question is when will rollback be need in general??
i saw that if i close the browser in the time the sub is running it occurs no problem and all the sub runs until the end
i thought that if a browser will be closed i would have problem with some values that are token from the page like
tbox_text_caption2.Text
that is the text from a textbox of a site
i thought that if the connection would close before the sub takes this value i would have a problem and then i need rollback..
is that right as i am thinking?




Reply With Quote