L
Luc
Hi,
Students can subscribe for any project via a webform. Table 'project '
contains all the proposed project and table 'student' contain the name of
the student and the project-id.
Now, suppose there is a limit of 4 students for project 'A' and there are
already 3 subscribed students for that project. One more student can choose
that project. The code checks whether the limit is not reached (by counting
the amount students for that project in table 'student') before inserting
that student in the table 'student'.
My problem is that when two students fills the webform for the same project
and click on the 'save-button' exactly at the same time, the code has no
time to check the limit and both students are nserted into table 'student'.
Is there a way to lock the table or something in order to preventing this?
Thanks
Luc
Here my code: (vb.net)
-----------------------
Protected Sub DetailsView2_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView2.ItemInserting
Dim student As Integer
Dim comd As SqlCommand
Dim sql, id As String
' check amount of student for project 'A' in table 'student'
Using mConnection As New SqlConnection(param.ConnectionString)
mConnection.Open()
sql = "select count(*) from student where id=@id"
comd = New SqlCommand(sql, mConnection)
comd.Parameters.AddWithValue("@id", 'A')
student = comd.ExecuteScalar
mConnection.Close()
End Using
If student = 4 Then
e.Cancel = True
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert('maximum students is reached');" & _
" window.location.href='start.aspx';", True)
End If
End Sub
Protected Sub DetailsView2_ItemInserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles
DetailsView2.ItemInserted
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert('you.are accepted');" & _
" window.location.href='start.aspx';", True)
End Sub
Students can subscribe for any project via a webform. Table 'project '
contains all the proposed project and table 'student' contain the name of
the student and the project-id.
Now, suppose there is a limit of 4 students for project 'A' and there are
already 3 subscribed students for that project. One more student can choose
that project. The code checks whether the limit is not reached (by counting
the amount students for that project in table 'student') before inserting
that student in the table 'student'.
My problem is that when two students fills the webform for the same project
and click on the 'save-button' exactly at the same time, the code has no
time to check the limit and both students are nserted into table 'student'.
Is there a way to lock the table or something in order to preventing this?
Thanks
Luc
Here my code: (vb.net)
-----------------------
Protected Sub DetailsView2_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView2.ItemInserting
Dim student As Integer
Dim comd As SqlCommand
Dim sql, id As String
' check amount of student for project 'A' in table 'student'
Using mConnection As New SqlConnection(param.ConnectionString)
mConnection.Open()
sql = "select count(*) from student where id=@id"
comd = New SqlCommand(sql, mConnection)
comd.Parameters.AddWithValue("@id", 'A')
student = comd.ExecuteScalar
mConnection.Close()
End Using
If student = 4 Then
e.Cancel = True
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert('maximum students is reached');" & _
" window.location.href='start.aspx';", True)
End If
End Sub
Protected Sub DetailsView2_ItemInserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles
DetailsView2.ItemInserted
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert('you.are accepted');" & _
" window.location.href='start.aspx';", True)
End Sub