Click here to Skip to main content
15,923,164 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questiongive an example for delegates in vb.net windows application Pin
vijaylumar23-Apr-08 23:35
vijaylumar23-Apr-08 23:35 
AnswerRe: give an example for delegates in vb.net windows application Pin
Arjun Marwaha24-Apr-08 1:57
Arjun Marwaha24-Apr-08 1:57 
GeneralCopy Data From One listbox to another on button click event Pin
sonia.sardana23-Apr-08 23:34
sonia.sardana23-Apr-08 23:34 
GeneralRe: Copy Data From One listbox to another on button click event Pin
Smithers-Jones23-Apr-08 23:47
Smithers-Jones23-Apr-08 23:47 
GeneralSplitting an image into multiple and Printing on multiple pages (to view image larger) Pin
anu_sam77723-Apr-08 23:32
anu_sam77723-Apr-08 23:32 
GeneralExcel VBA set cell background to "Transparent" (not vbWhite) Pin
devvvy23-Apr-08 22:52
devvvy23-Apr-08 22:52 
GeneralRe: Excel VBA set cell background to "Transparent" (not vbWhite) Pin
Smithers-Jones23-Apr-08 23:30
Smithers-Jones23-Apr-08 23:30 
GeneralThe sqlcommand is currently busy open, fetching Pin
Eunice (VB junior)23-Apr-08 15:25
Eunice (VB junior)23-Apr-08 15:25 
Hi,
I'm trying to create a transaction code within a button click by performing the insert/update/select. Purpose is to make sure every operation can be rollback instead of some table inserted but some not. But I get this error:

The SqlCommand is currently busy Open, Fetching.
Description: "System.InvalidoperationException. The sqlCommand is currently busy open,Fetching."

It happened at "cmd.ExecuteNonQuery()" (the insert command after select command). Line 52 from my codes.


Here is my codes. Can anyone help me? Thanks a lot.

Dim cn As New SqlClient.SqlConnection
cn.ConnectionString = ("server=samtest;uid=sa;pwd=sa;database=Test")
Dim cmd As New SqlClient.SqlCommand
Dim tn As SqlClient.SqlTransaction

Try
cmd.Connection = cn
If cn.State = ConnectionState.Closed Then cn.Open()
tn = cn.BeginTransaction
cmd.Transaction = tn

j = 0
For j = 0 To jcounter - 1
Dim DefID As Object = dgItem.Item(j, 0)
Dim Component As Object = dgItem.Item(j, 1)
Dim QtyOut As Object = dgItem.Item(j, 3)
Dim FailQty As Object = dgItem.Item(j, 4)
Dim Type As Object = dgItem.Item(j, 5)

cmd.CommandText = "Insert into LCDTest (UnitID,TestDefID,Component,PassQty,FailQty,Type) values(" & lblUnitID.Text & "," & DefID.ToString() & ",'" & Component.ToString() & "'," & QtyOut.ToString() & "," & FailQty.ToString() & ",'" & Type.ToString() & "')"
cmd.ExecuteNonQuery()
Next


If icounter > 0 Then
i = 0
For i = 0 To icounter - 1
Dim DefID As Object = dgResult.Item(i, 0)
Dim Component As Object = dgResult.Item(i, 1)
Dim FailureCode As Object = dgResult.Item(i, 2)
Dim RejQty As Object = dgResult.Item(i, 3)
Dim Remark As Object = dgResult.Item(i, 4)

cmd.CommandText = "Select ID from LCDTest WHERE UnitID = " & lblUnitID.Text & " and stationid=" & Me.lblStationID.Text & " and TestDefID =" & DefID.ToString() & " "
dr = cmd.ExecuteReader()

If dr.Read() Then
lblTestID.Text = dr(0).ToString()
Else
MessageBox.Show("No such ID. Please scan again.")
lblTestID.Focus()
Exit Sub
End If

cmd.CommandText = "Insert into LCDMeasurementFail (UnitID,TestID,Component,FailureCode,RejectQty) values ( " & lblUnitID.Text & "," & lblTestID.Text & ",'" & Component.ToString() & "','" & FailureCode.ToString() & "'," & RejQty.ToString() & ")"
cmd.ExecuteNonQuery()
Next

End If


If lblSort1.Text = 0 Then

Dim strQuery3 As String
cmd.CommandText = "Update LCDUnit set Loopend = '" & 2 & "', CloseTime= getdate() where id = " & lblUnitID.Text & " "
cmd.ExecuteNonQuery()

End If

tn.Commit()
cn.Close()
MessageBox.Show("Successful")


Catch ex As Exception
tn.Rollback()
cn.Close()
MessageBox.Show(ex.Message)

Finally
cn.Close()
End Try
QuestionCrystal Reports deployment Pin
Jodd23-Apr-08 12:19
Jodd23-Apr-08 12:19 
GeneralRe: Crystal Reports deployment Pin
Steven J Jowett23-Apr-08 12:33
Steven J Jowett23-Apr-08 12:33 
GeneralRe: Crystal Reports deployment Pin
Jodd23-Apr-08 13:29
Jodd23-Apr-08 13:29 
GeneralDeveloping applications for BlackBerry Pin
Mr Oizo23-Apr-08 4:50
Mr Oizo23-Apr-08 4:50 
GeneralRe: Developing applications for BlackBerry Pin
Thomas Stockwell23-Apr-08 8:24
professionalThomas Stockwell23-Apr-08 8:24 
QuestionError QueryInterface while trying to use VB6 DLL into VB.NET project Pin
mandrake_223-Apr-08 4:45
mandrake_223-Apr-08 4:45 
Questionsetting a variable for multiple threads Pin
Tom Deketelaere23-Apr-08 4:23
professionalTom Deketelaere23-Apr-08 4:23 
GeneralRe: setting a variable for multiple threads Pin
Luc Pattyn23-Apr-08 11:04
sitebuilderLuc Pattyn23-Apr-08 11:04 
GeneralRe: setting a variable for multiple threads Pin
Tom Deketelaere23-Apr-08 23:10
professionalTom Deketelaere23-Apr-08 23:10 
GeneralFile Open/Close Pin
ritz123423-Apr-08 3:06
ritz123423-Apr-08 3:06 
GeneralRe: File Open/Close Pin
Dave Kreskowiak23-Apr-08 3:38
mveDave Kreskowiak23-Apr-08 3:38 
GeneralRe: File Open/Close Pin
ritz123423-Apr-08 4:32
ritz123423-Apr-08 4:32 
GeneralRe: File Open/Close Pin
Dave Kreskowiak23-Apr-08 9:59
mveDave Kreskowiak23-Apr-08 9:59 
GeneralProblem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 1:14
Balagurunathan S23-Apr-08 1:14 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 1:17
darkelv23-Apr-08 1:17 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 1:27
Balagurunathan S23-Apr-08 1:27 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 1:38
darkelv23-Apr-08 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.