Dim blUser As Boolean
為西豐等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及西豐網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為網(wǎng)站設計、成都網(wǎng)站制作、西豐網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
Dim sql_conn As New SqlClient.SqlConnection("data source=.;initial catalog=test;user id=sa;password=123456;")
sql_conn.Open()
Dim sql_comm As New SqlClient.SqlCommand("Select user from table where user='123'", sql_conn)
Dim reader As SqlClient.SqlDataReader
reader = sql_comm.ExecuteReader
reader.Read()
If reader.HasRows Then
blUser = True
End If
reader.Close()
sql_conn.Close()
Dim DbCmd as New oledbCommand
DbCmd.CommandType = CommandType.Text
DbCmd.CommandText = CommandText
dim rowsCount as integer = cint(val(DbCmd.ExecuteScalar(select count(*) from table) ""))
直接打開EXCEL用CTRL+F ,可以直接定位到符合條件的數(shù)據(jù);或用指定條件篩選
select * from 表 where
(case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end) BETWEEN 2 and 5
以下是完整模塊
Imports
System.Data
Imports
System.IO
Imports
System.Data.OleDb
Module
Module1
Public
cn
As
New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
Application.StartupPath
"\mdb數(shù)據(jù)庫名字.mdb")
'定義連接
Public
DataBaseRST
As
Integer
'用來返回數(shù)據(jù)庫執(zhí)行結果
Public
Function
DataModify(ByVal
str
As
String)
As
Boolean
'進行數(shù)據(jù)庫修改操作
Dim
cmdinsert
As
New
OleDbCommand
Try
cmdinsert.CommandText
=
str
cmdinsert.Connection
=
cn
If
cn.State
=
ConnectionState.Closed
Then
cn.Open()
DataBaseRST
=
cmdinsert.ExecuteNonQuery()
'用來返回執(zhí)行的結果
cn.Close()
Return
True
Catch
ex
As
Exception
MessageBox.Show(Err.Description,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Return
False
End
Try
End
Function
Public
Function
Search(ByVal
str
As
String,
ByVal
DGV
As
DataGridView)
As
Boolean
'查詢
str---查詢命令,DGV---DataGridView,用來顯示數(shù)據(jù)的控件
Dim
tb
As
New
DataTable
Try
Dim
ap
As
New
OleDb.OleDbDataAdapter(str,
cn)
ap.Fill(tb)
DGV.DataSource
=
tb
Return
True
Catch
ex
As
Exception
MessageBox.Show(Err.Description,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Return
False
End
Try
End
Function
End
Module
'以下是調用方法
DataModify("
insert
into
aa
values
('1','2')")'-------這里是數(shù)據(jù)庫更新操作
Search("select
bb
from
aa",DataGridView1)'-----------這里是數(shù)據(jù)表查詢操作
1.新建一張表格,在表格中導入學生的成績表,如圖所示,將建立一個按鈕,通過它來實現(xiàn)查找。
2.單擊菜單欄中的“開發(fā)工具”——插入——表單控件——按鈕,在出現(xiàn)的十字箭頭上拖住畫出一個按鈕,如圖所示。
3.在彈出的查找紅對話框中選擇“錄制”,在彈出的“錄制新宏”對話框中,修改宏名稱為“查找”,單擊確定。
4. 單擊“開發(fā)工具”——查看代碼,打開VBA編輯器,如圖所示。
5.現(xiàn)在輸入代碼:
Sub 查找()
Dim jieguo As String, p As String, q As String
Dim c As Range
jieguo = Application.InputBox(prompt:="請輸入要查找的值:", Title:="查找", Type:=2)
If jieguo = "False" Or jieguo = "" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.Cells
? Set c = .Find(jieguo, , , xlWhole, xlByColumns, xlNext, False)
? If Not c Is Nothing Then
? ? ? p = c.Address
? ? ? Do
? ? ? ? ? c.Interior.ColorIndex = 4
? ? ? ? ? q = q c.Address vbCrLf
? ? ? ? ? Set c = .FindNext(c)
? ? ? Loop While Not c Is Nothing And c.Address p
? End If
End With
MsgBox "查找數(shù)據(jù)在以下單元格中:" vbCrLf vbCrLf _
? q, vbInformation + vbOKOnly, "查找結果"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
6.現(xiàn)在回到EXCEL表格,右擊按鈕,選擇“編輯文字”,修改按鈕名稱為“查找按鈕”。
7. 現(xiàn)在單擊查找按鈕,出現(xiàn)對話框“請輸入要查找的值”,在方框中輸入“男”,單擊確定,出現(xiàn)對話框“查找數(shù)據(jù)在一下單元格中”,單擊確定,對應單元格就變成了亮色。
名稱欄目:vb.net查詢表中數(shù)據(jù) vb實現(xiàn)數(shù)據(jù)庫查詢
瀏覽地址:http://jinyejixie.com/article16/docpjgg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、用戶體驗、網(wǎng)站策劃、面包屑導航、網(wǎng)站設計公司、Google
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)