C#与VB.NET删除Access数据库
C#与VB.NET删除数据库
- VB.NET删除数据库内容
1:VB.NET删除数据库内容,其代码如下:
''' <summary>
''' 删除数据库
''' </summary>
''' <param name="filepath">数据库的路径</param>
''' <returns>true:删除成功</returns>
''' <remarks></remarks>
Public Function DataDelete(ByVal filepath As String)
Dim bolReturn As Boolean = False
Try
'连接数据库
Dim oleCon As OleDbConnection = getConnection(filepath)
'打开数据库
If (oleCon.State = ConnectionState.Open) Then oleCon.Close()
oleCon.Open()
'执行语句
Dim strCmd As String = "delete * from Administrator where 名字='张三'"
Dim oleCmd As OleDbCommand = New OleDbCommand(strCmd, oleCon)
oleCmd.ExecuteNonQuery()
oleCon.Close()
bolReturn = True
Catch ex As Exception
MessageBox.Show("删除失败", "数据库提示")
End Try
Return bolReturn
End Function
2:完成效果如图所示:

- C#删除数据库内容
1:C#删除数据库内容,其代码如下:
''' <summary>
''' 删除数据库
''' </summary>
''' <param name="filepath">数据库的路径</param>
''' <returns>true:删除成功</returns>
''' <remarks></remarks>
Public Function DataDelete(ByVal filepath As String)
Dim bolReturn As Boolean = False
Try
'连接数据库
Dim oleCon As OleDbConnection = getConnection(filepath)
'打开数据库
If (oleCon.State = ConnectionState.Open) Then oleCon.Close()
oleCon.Open()
'执行语句
Dim strCmd As String = "delete * from Administrator where 名字='张三'"
Dim oleCmd As OleDbCommand = New OleDbCommand(strCmd, oleCon)
oleCmd.ExecuteNonQuery()
oleCon.Close()
bolReturn = True
Catch ex As Exception
MessageBox.Show("删除失败", "数据库提示")
End Try
Return bolReturn
End Function
2:完成效果如图所示:


浙公网安备 33010602011771号