How to Lock a Table in SQL SERVER Using VB.NET
The following code shows how to Lock a Table in SQL SERVER Using VB.NET
Step1:Create Window based project and select language as VB.NET
Step2:Add a button control named CmdFill set its properties Text="Fill" and a datagrid named Datagrid1
Step3:Implement the following Code
Dim txn As SqlTransaction
Dim ds As New DataSet
Dim con As New SqlConnection("Data source=sourcename;Initial catalog=Northwind;uid=gopi;pwd=gopi")
Private Sub CmdFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdFill.Click
txn = con.BeginTransaction(IsolationLevel.RepeatableRead)
adp.SelectCommand.Transaction = txn
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Customers"
Step 4: Run the program and click the Fill Button.Datagrid will be filled with customers table.
Step 5:Go to SQL server.Select query analyzer and run this query
update customers set contactname='Gopi' where contactname='Antonio Moreno'
Step 6:You will find the query executing with out doing any changes until you close your application form.
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you