2012-11-21 7 views
-1

안녕 얘들 아 여기서 내 코드에 대한 도움이 필요하다. 어디에서 연결이 닫히는 지 알 수 없다. 내가 원하는 것은 msgbox에서 no를 클릭 할 때까지 레코드를 계속 추가하는 것이다.이 연결을 닫으면 어떻게됩니까?

heres my code :

Dim connstr As String = "server=localhost; uid= root; password=root; database=lmsdbase;" 
Dim conn As MySqlConnection = New MySqlConnection 
Dim ds As New DataSet 
Dim da As MySqlDataAdapter 


    conn.ConnectionString = connstr 



    Try 
     If conn.State = ConnectionState.Closed Then 
      conn.Open() 
     Else 
      conn.Close() 
      MsgBox("Database Connection Error") 
     End If 
    Catch ex As Exception 
     MsgBox(Err.Description) 

     txtBookISBN.Focus() 

    End Try 



    Dim SqlStatement As String = "INSERT INTO tblIssue(ISBN, Title, BorrowerID, Name, Occupation, BorrowerType, School, DateIssued, DateToBeReturned) VALUES('" & txtBookISBN.Text & "','" & txtBTitle.Text & "','" & txtMemID.Text & "','" & txtMemName.Text & "','" & txtOccupation.Text & "','" & cboBtype.Text & "','" & txtSchool.Text & "','" & DateTimePicker1.Text & "','" & DateTimePicker2.Text & "')" 
    Save(SqlStatement) 

    Public Sub Save(ByRef SqlStatement As String) 
    Dim cmd As MySqlCommand = New MySqlCommand 

    With cmd 

     .CommandText = SqlStatement 
     .CommandType = CommandType.Text 
     .Connection = conn 
     .ExecuteNonQuery() 

    End With 

    'conn.Close() 
    MsgBox("Success!") 


    If MsgBox("Do You Want to Add New Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 



     txtMemID.Text = "" 
     txtMemName.Text = "" 
     txtBookISBN.Text = "" 
     txtBTitle.Text = "" 
     txtOccupation.Text = "" 
     cboBtype.Text = "" 
     txtSchool.Text = "" 

     txtMemID.Focus() 

    Else 


     Me.Close() 


    End If 

    conn.Dispose() 

End Sub 

정말

+2

실행하는 동안 오류가 있습니까? – Gayatri

답변

1
If conn.State = ConnectionState.Closed Then 
      conn.Open() 
     Else 
      conn.Close() 
      MsgBox("Database Connection Error") 

이 아닌이 열려있는 모든 연결을합니까 당신의 도움을 주셔서 감사합니다?

+0

왜 디버깅 및 확인 하시겠습니까? –

+2

이미 가지고있어 ... 내가 넣어 다른 코드와 충돌이있다. –

+0

@BoyGeorge 조지 : 잘 했어 :) –

관련 문제