重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.netsql6的简单介绍

使用VB.net实现sql数据库的备份与恢复代码

Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click 备份数据库 BACKUP DATABASE Test TO DISK= C:\Backup WITH Format Dim cn As SqlConnection Dim cm As SqlCommand cn = getDB() cm = New SqlCommand( BACKUP DATABASE JXbase TO DISK= C:\Backup WITH Format cn) cn Open() cm ExecuteNonQuery() MsgBox( 备份成功 ) cn Close()

创新互联主营新绛网站建设的网络公司,主营网站建设方案,成都app软件开发公司,新绛h5微信平台小程序开发搭建,新绛网站营销推广欢迎新绛等地区企业咨询

End Sub

恢复 Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click Dim cn As New SqlConnection Dim cn As New SqlConnection Dim mydr As SqlDataReader Dim str As String

Dim tmpConnectionString As String = Data Source=JJK;Initial Catalog=master;Integrated Security=True cn ConnectionString = tmpConnectionString cn ConnectionString = tmpConnectionString cn Open() cn Open() Dim cm As SqlCommand = New SqlCommand( select spid from master sysprocesses where dbid=db_id( JXbase ) cn) mydr = cm ExecuteReader()

Dim cm As SqlCommand = New SqlCommand() cm Connection = cn

While (mydr Read()) 杀死进程

str = kill mydr( spid ) ToString() cm CommandText = str cm CommandType = CommandType Text Application DoEvents() cm ExecuteNonQuery() 杀进程 End While mydr Close() cm = New SqlCommand( RESTORE DATABASE JXbase FROM DISK= C:\Backup cn) 恢复备份 cm ExecuteNonQuery() MsgBox( 恢复成功成功 ) cn Close() cn Close()

lishixinzhi/Article/program/net/201311/12901

vb.net 中如何使用SQL语句查询数据库

dim

myselectquery

as

string

=

"select

*

from

表1

where

姓名='小强'"

dim

mycommand

as

new

sqlcommand

(myselectquery,

conn)

'建立一个command控件,conn是你的sqlconnection对象

conn.open()'打开数据连接

dim

myreader

as

sqldatareader'定义一个reader用来读数据

myreader

=

mycommand.executereader()'运行你的查询,结果到myreader

if

myreader.read()

then

'如果查到了数据

msgbox(myreader.getstring(0))

'显示第一个字段

end

if

vb.net 中如何使用SQL语句查询数据库中的数据

1、首先打开Visual Studio 2008代码窗口,添加引用。

2、输入以下代码:Public conn1  As SqlConnection = New SqlConnection 。

3、声明关键字 Public;(因为是全局变量,所以用Public 来声明)。

4、如果SQL 数据库就在本机,则用以下代码连接。

5、如果代码太长,影响可读性,可以用空格加"_"后,回车换行即可。


新闻名称:vb.netsql6的简单介绍
URL网址:http://cqcxhl.cn/article/dojeoeh.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP