Logo 
Search:

VB.Net Forum

Ask Question   UnAnswered
Home » Forum » VB.Net       RSS Feeds

The connection cannot be used to perform this operation. It is either closed or invalid in this

  Asked By: Qaiser    Date: Oct 04    Category: VB.Net    Views: 907
  

please help me what should i do for this error....
please.....

Dim SAVOK As Boolean, i As Integer
Dim ACCOUNT As ADODB.Recordset
Dim PARTY As ADODB.Recordset
Dim cATYP As String

PARTY = Nothing
ACCOUNT = Nothing
ACCOUNT = New ADODB.Recordset
PARTY = New ADODB.Recordset

SAVOK = False
cATYP = ""
If (txtcAcode.Text = "") Or (TxtcAname.Text = "") Then
MsgBox("Unabale to Save the Empty Code", vbCritical + vbOKOnly, Application.CompanyName)
Exit Sub
End If

PARTY.Open("SELECT * FROM [ACCOUNT] WHERE [ACODE] = '" & txtcAcode.Text & "'", MYDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If PARTY.RecordCount > 0 Then
MsgBox("The Code Exists in Party Definition, Try Some Other Code", vbCritical + vbOKOnly, )
Exit Sub
End If
PARTY = Nothing

On Error GoTo ERRHNDL
MYDB.BeginTrans()

MYDB.Execute("Delete from ACCOUNT Where ACODE='" & CStr(txtcAcode.Text) & "'")

PARTY.Open("SELECT * FROM [ACCOUNT]", MYDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic)
cATYP = 14

If nAIname0.Checked = True Then
cATYP = 0
cATYP = nAIname0.Text
SAVOK = True
ElseIf nAIname1.Checked = True Then
cATYP = 1
cATYP = nAIname1.Text
SAVOK = True
ElseIf nAIname2.Checked = True Then
cATYP = 2
cATYP = nAIname2.Text
SAVOK = True
ElseIf nAIname3.Checked = True Then
cATYP = 3
cATYP = nAIname3.Text
SAVOK = True
ElseIf nAIname4.Checked = True Then
cATYP = 4
cATYP = nAIname4.Text
SAVOK = True
ElseIf nAIname5.Checked = True Then
cATYP = 5
cATYP = nAIname5.Text
SAVOK = True
ElseIf nAIname6.Checked = True Then
cATYP = 6
cATYP = nAIname6.Text
SAVOK = True
ElseIf nAIname7.Checked = True Then
cATYP = 7
cATYP = nAIname7.Text
SAVOK = True
ElseIf nAIname8.Checked = True Then
cATYP = 8
cATYP = nAIname8.Text
SAVOK = True
ElseIf nAIname9.Checked = True Then
cATYP = 9
cATYP = nAIname9.Text
SAVOK = True
ElseIf nAIname10.Checked = True Then
cATYP = 10
cATYP = nAIname10.Text
SAVOK = True
ElseIf nAIname11.Checked = True Then
cATYP = 11
cATYP = nAIname11.Text
SAVOK = True
ElseIf nAIname12.Checked = True Then
cATYP = 12
cATYP = nAIname12.Text
SAVOK = True
ElseIf nAIname13.Checked = True Then
cATYP = 13
cATYP = nAIname13.Text
SAVOK = True
End If

If SAVOK = False Then
Exit Sub
End If

If (cATYP = 0) Or (cATYP = 2) Or (cATYP = 3) Or (cATYP = 6) Then
If ACCOUNT.RecordCount > 0 Then
ACCOUNT.MoveFirst()
End If
ACCOUNT.Find("[ATYPE] = " & cATYP)
If ACCOUNT.EOF Then
ACCOUNT.AddNew()

ACCOUNT.Fields("ACODE").Value = CStr(txtcAcode.Text)
ACCOUNT.Fields("ANAME").Value = CStr(TxtcAname.Text)
ACCOUNT.Fields("ATYPE").Value = Val(cATYP)
'ACCOUNT.Fields("Bal").Value = Val(0)
ACCOUNT.Fields("ATYPNAME").Value = CStr(cATYP)
'ACCOUNT.ATPNAME = CStr(Left$(nATPNAME(nVAL).Caption, 15))

ACCOUNT.Update()
End If
End If
MYDB.CommitTrans()
ACCOUNT = Nothing
txtcAcode.Text = ""
TxtcAname.Text = ""
nAIname13.Checked = True
Refresh()
Me.ACCOUNTTableAdapter.Fill(Me.Account13DataSet1.ACCOUNT)
DataGridView1.Rows.Clear()

DataGridView1.Refresh()
txtcAcode.Focus()

Exit Sub
ERRHNDL:
MsgBox(Err.Number & vbCrLf & Err.Description, vbCritical + vbOKOnly, Application.CompanyName)
Exit Sub

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: