2015-04-11 3 views
0

после удаления записи из формы есть пустая запись до Клоса формы и открыть это ниже мой кодпустая записи после удаления из набора данных

Try 

     Dim delrecord As String = "delete from unitinfo where unitCode = '" & txtUcode.Text & "' " 
     Dim delcon As New SqlConnection(sqlcon) 

     delcon.Open() 
     Dim cmdsqldel As New SqlCommand(delrecord, delcon) 
     cmdsqldel.ExecuteNonQuery() 
     If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then 

      Exit Sub 
     Else 

     End If 
     delcon.Close() 

    Catch ex As Exception 

    End Try 
+3

Примечания стороны, ваш MessageBox является бит слишком поздно. – Steve

+1

... и почти каждая строка кода имеет проблему с ней. Начните с изучения параметров SQL и удалите пустой Try/Catch. – Plutonix

+0

И пока вы на нем, исследуйте, как обращаться с одноразовыми объектами. –

ответ

0
Try 

     If MessageBox.Show("Do you really want to Delete this Record?", 
"Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then 

      Exit Sub 
     Else 
     Dim delrecord As String = "delete from unitinfo 
           where unitCode = '" & txtUcode.Text & "' " 
     Dim delcon As New SqlConnection(sqlcon) 
     delcon.Open() 
     Dim cmdsqldel As New SqlCommand(delrecord, delcon) 
     cmdsqldel.ExecuteNonQuery() 
     delcon.Close() 
     MessageBox.Show("Record Successfuly Deleted") 
     /* Here you should refresh your datagridview if you have or any thing else*/ 
     End If 

    Catch ex As Exception 
    MessageBox.Show(ex.Message) 
    Finally 
    ' This line executes whether or not the exception occurs.' 
    If delcon.State = ConnectionState.Open Then delcon.Close() 

    End Try 
Смежные вопросы