ACmd.CommandText = AFind 下面要加上一句执行
ACmd.ExecuteNonQuery()
-------------------------------------
要写查询到控件DataGridView的话,可以这样做:.net2.0或以上的环境中:
Dim AConnect As OleDb.OleDbConnection
Dim ACmd As OleDb.OleDbCommand
Dim dtResult As DataTable=new DataTable()
Dim ConnectStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Enroll.mdb"
Dim AFind As String = "SELECT * FROM rj"
AConnect = New OleDb.OleDbConnection(ConnectStr)
AConnect.Open()
ACmd = New OleDb.OleDbCommand(AFind, AConnect)
ACmd.CommandText = AFind
Dim ADr as OleDb.OleDbDataReader=ACmd.ExcuteReader()
dtResult.Load(ADr)
AConnect.Close()
DataGridView.DataSource=dtResult
---------
希望能符合你的需求
下面是我的两个函数,希望对你又帮助:
Function Getdata(ByVal Sqlstr As String) As DataTable '取得数据
Dim Connstr As String = "provider=SQLOLEDB;data source=" & ServerName & ";initial catalog=" & DBName & ";user id =" & DBUserName & ";password=" & DBUserPwd
Dim SqlConn As New OleDb.OleDbConnection(Connstr)
Dim SqlCmd As New OleDb.OleDbCommand(Sqlstr, SqlConn)
Dim TmpDst As New DataSet
Dim TmpAda As New OleDb.OleDbDataAdapter
TmpAda.TableMappings.Add("table", "temp")
TmpAda.SelectCommand = SqlCmd
SqlConn.Open()
SqlCmd.ExecuteNonQuery()
SqlConn.Close()
TmpAda.Fill(TmpDst, "temp")
Return TmpDst.Tables("temp")
End Function
Function Gengxindata(ByVal Sqlstr As String) As Boolean '更新数据
Try
Dim Connstr As String = "Provider=SQLOLEDB;data source=" & ServerName & ";initial catalog=" & DBName & ";user id =" & DBUserName & ";password=" & DBUserPwd
Dim SqlConn As New OleDb.OleDbConnection(Connstr)
Dim SqlCmd As New OleDb.OleDbCommand(Sqlstr, SqlConn)
SqlConn.Open()
SqlCmd.ExecuteNonQuery()
SqlConn.Close()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
End Function
看你连接的是access数据库,只要把函数里面的链接字符串改一下就可以了!
对数据库的查询返回结果:
dim TSqlStr1 as string="你的sql语句"
datagridview.datasource=getdata(TSqlStr1)'getdata()是上面第一个函数
好复杂的问题了。。。
百度上是不太可能问得到,建议楼主到专业点的论坛上发帖问比较好~~