vb.net 中如何使用SQL语句查询数据库
2个回答
展开全部
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
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
展开全部
我是这样做的:
Dim
ConnectionString
As
String
=
_
"Provider=Microsoft.Jet.OleDb.4.0;_DatacSource
=
App.Path+\temp.mdb"
Dim
myconn
As
OleDbConnection
=
New
OleDbConnection()
myconn.ConnectionString
=
ConnectionString
Dim
strcom
As
String
=
"select
*
form
通讯录"
OleDbConnection1.Open()
Dim
strdele
As
String="DELTEL
表
WHERE
姓名='MMM'"
Dim
mycommand
As
OleDbCommand
=
New
OleDbCommand(strdele,
myconn)
mycommand.ExecuteNonQuery()
'从数据库中删除记录
DataSet1.Tables("通讯录").Rows(mybind.Position).Delete()
'逻辑删除
DataSet1.Tables("通讯录").AcceptChanges()
OleDbConnection1.Close()
Dim
ConnectionString
As
String
=
_
"Provider=Microsoft.Jet.OleDb.4.0;_DatacSource
=
App.Path+\temp.mdb"
Dim
myconn
As
OleDbConnection
=
New
OleDbConnection()
myconn.ConnectionString
=
ConnectionString
Dim
strcom
As
String
=
"select
*
form
通讯录"
OleDbConnection1.Open()
Dim
strdele
As
String="DELTEL
表
WHERE
姓名='MMM'"
Dim
mycommand
As
OleDbCommand
=
New
OleDbCommand(strdele,
myconn)
mycommand.ExecuteNonQuery()
'从数据库中删除记录
DataSet1.Tables("通讯录").Rows(mybind.Position).Delete()
'逻辑删除
DataSet1.Tables("通讯录").AcceptChanges()
OleDbConnection1.Close()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询