below is the code
" Dim i As Integer = 0
Do While (i < CheckBoxList1.Items.Count)
If CheckBoxList1.Items(i).Selected Then
Dim cmdDistrict As New SqlCommand("AssociateDistricts", cnnContact)
cmdDistrict.CommandType = CommandType.StoredProcedure
Try
With cmdDistrict.Parameters
If blnIsUpdate Then
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
' .Add("@UserDistrictId", SqlDbType.BigInt).Value = CInt(litDistrictUser.Text.Trim())
Else
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
End If
.Add("@DistrictId", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
'If CheckBoxList2.Items(i).Selected = False Then
' .Add("@TehsilId", SqlDbType.BigInt).Value = 0
'End If
' .Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(i).Value)
.Add("UserId", SqlDbType.TinyInt).Value = litUserId.Text
.Add("@IsSelcted", SqlDbType.Bit).Value = True
.Add("@DistrictName", SqlDbType.NVarChar).Value = CheckBoxList1.Items(i).Text
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
.Add("@ReturnId", SqlDbType.BigInt).Direction = ParameterDirection.Output
End With
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdDistrict.Transaction = trnContact
cmdDistrict.ExecuteNonQuery()
trnContact.Commit()
cnnContact.Close()
Dim j As Integer = 0
Dim k As Integer = 0
Dim L As Integer = 0
Do While (j < CheckBoxList2.Items.Count)
If CheckBoxList2.Items(j).Selected Then
Dim cmdsDistrict As New SqlCommand("AddTehsil", cnnContact)
cmdsDistrict.CommandType = CommandType.StoredProcedure
Try
With cmdsDistrict.Parameters
If blnIsUpdate Then
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
' .Add("@UserDistrictId", SqlDbType.BigInt).Value = CInt(litDistrictUser.Text.Trim())
Else
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
End If
.Add("@DistrictId", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
.Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(j).Value)
'GetListBoxSelStringInCommaTehsil(CheckBoxList2)
'CInt(CheckBoxList2.Items(j).Value)
.Add("UserId", SqlDbType.TinyInt).Value = litUserId.Text
.Add("@IsSelcted", SqlDbType.Bit).Value = True
.Add("@DistrictName", SqlDbType.NVarChar).Value = CheckBoxList1.Items(i).Text
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
.Add("@ReturnId", SqlDbType.BigInt).Direction = ParameterDirection.Output
'.Add("@DistrictID", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
End With
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdsDistrict.Transaction = trnContact
'GetDistrictId()
cmdsDistrict.ExecuteNonQuery()
trnContact.Commit()
cnnContact.Close()
Catch ex As Exception
End Try
End If
Do While (k < CheckBoxList3.Items.Count)
If CheckBoxList3.Items(k).Selected Then
Dim cmdsDistrictd As New SqlCommand("AddUcs", cnnContact)
cmdsDistrictd.CommandType = CommandType.StoredProcedure
Try
With cmdsDistrictd.Parameters
If blnIsUpdate Then
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
' .Add("@UserDistrictId", SqlDbType.BigInt).Value = CInt(litDistrictUser.Text.Trim())
Else
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
End If
.Add("@DistrictId", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
If CheckBoxList2.Items(j).Selected = True Then
.Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(j).Value)
Else
.Add("@TehsilId", SqlDbType.BigInt).Value = DBNull.Value
End If
' .Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(j).Value)
'GetListBoxSelStringInCommaTehsil(CheckBoxList2)
'CInt(CheckBoxList2.Items(j).Value)
.Add("@UcId", SqlDbType.BigInt).Value = CInt(CheckBoxList3.Items(k).Value)
.Add("UserId", SqlDbType.TinyInt).Value = litUserId.Text
.Add("@IsSelcted", SqlDbType.Bit).Value = True
.Add("@DistrictName", SqlDbType.NVarChar).Value = CheckBoxList1.Items(i).Text
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
.Add("@ReturnId", SqlDbType.BigInt).Direction = ParameterDirection.Output
'.Add("@DistrictID", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
End With
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdsDistrictd.Transaction = trnContact
cmdsDistrictd.ExecuteNonQuery()
trnContact.Commit()
cnnContact.Close()
Catch ex As Exception
End Try
End If
Do While (L < CheckBoxList4.Items.Count)
If CheckBoxList4.Items(L).Selected Then
Dim cmdsDistrict As New SqlCommand("AddVillages", cnnContact)
cmdsDistrict.CommandType = CommandType.StoredProcedure
Try
With cmdsDistrict.Parameters
If blnIsUpdate Then
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
' .Add("@UserDistrictId", SqlDbType.BigInt).Value = CInt(litDistrictUser.Text.Trim())
Else
.Add("@UserDistrictId", SqlDbType.BigInt).Value = DBNull.Value
End If
.Add("@DistrictId", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
If CheckBoxList2.Items(j).Selected = True Then
.Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(j).Value)
Else
.Add("@TehsilId", SqlDbType.BigInt).Value = DBNull.Value
End If
'.Add("@TehsilId", SqlDbType.BigInt).Value = CInt(CheckBoxList2.Items(j).Value)
' GetListBoxSelStringInCommaTehsil(CheckBoxList2)
'CInt(CheckBoxList2.Items(j).Value)
If CheckBoxList3.Items(k).Selected = True Then
.Add("@UcId", SqlDbType.BigInt).Value = CInt(CheckBoxList3.Items(k).Value)
Else
.Add("@UcId", SqlDbType.BigInt).Value = DBNull.Value
End If
'.Add("@UcId", SqlDbType.BigInt).Value = CInt(CheckBoxList3.Items(k).Value)
.Add("@villageId", SqlDbType.BigInt).Value = CInt(CheckBoxList4.Items(L).Value)
.Add("UserId", SqlDbType.TinyInt).Value = litUserId.Text
.Add("@IsSelcted", SqlDbType.Bit).Value = True
.Add("@DistrictName", SqlDbType.NVarChar).Value = CheckBoxList1.Items(i).Text
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
.Add("@ReturnId", SqlDbType.BigInt).Direction = ParameterDirection.Output
'.Add("@DistrictID", SqlDbType.BigInt).Value = CInt(CheckBoxList1.Items(i).Value)
End With
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdsDistrict.Transaction = trnContact
cmdsDistrict.ExecuteNonQuery()
trnContact.Commit()
cnnContact.Close()
Catch ex As Exception
End Try
End If
L = (L + 1)
Loop
k = (k + 1)
Loop
j = (j + 1)
Loop
Catch ex As Exception
End Try
End If
i = (i + 1)
Loop
cnnContact.Close()
On local it works fine but when i connect to the database live it does not save and it does not show any error of timeout or else please check if any one know
On local it works fine but when i connect to the database live it does not save and it does not show any error of timeout or else please check if any one know


Joginder BangerRank #360 · 7K reputationPosted Nov 30, 2014, 9:00 PM EST
Kunal VaishyaRank #990 · 2K reputationPosted Dec 2, 2014, 7:57 PM EST
Hi first use only one try catch in your code,
Second thing your code is too long can you please describe more that which type error coming in Exception block.
Please check Stored Procedures also, may are passing null values in SP instead of require values.
Regards,
Kunal.
Danish HabibRank #2,024 · 715 reputationPosted Dec 2, 2014, 8:50 PM EST
Joginder BangerRank #360 · 7K reputationPosted Dec 2, 2014, 9:28 PM EST
Make a simple table about your data. share it after that we can assume what is the best way for your performance issue.
Note:- Why are used the loop, i suggestion you make a function in database and join, it be boost your performance.
Danish HabibRank #2,024 · 715 reputationPosted Dec 2, 2014, 9:34 PM EST