vbnet查询文件,vbnet读取文件内容
在vb.net中如何查询MDB数据库的数据
以下是完整模块
创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的凤翔网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
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数据库名字.mdb") '定义连接
Public DataBaseRST As Integer '用来返回数据库执行结果
Public Function DataModify(ByVal str As String) As Boolean '进行数据库修改操作
Dim cmdinsert As New OleDbCommand
Try
cmdinsert.CommandText = str
cmdinsert.Connection = cn
If cn.State = ConnectionState.Closed Then cn.Open()
DataBaseRST = cmdinsert.ExecuteNonQuery() '用来返回执行的结果
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,用来显示数据的控件
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')")'-------这里是数据库更新操作
Search("select bb from aa",DataGridView1)'-----------这里是数据表查询操作
vb.net 搜索子目录下的文件
vb.net编程查找搜索指定目录下面的所有文件和其子目录下的文件,方法如下:
''=============================================
''名称: FindPath
''作用: 查找搜索指定目录下面的所有文件和其子目录下的文件
''参数:strPath 要查找的目录,
''strFiles 用于存查找结果的缓冲区,String 类型的动态数组,调用时事先初始化, 如Redim strFiles(0)
''FileCount 用于返回文件个数
''=============================================
Public Sub FindPath(ByVal strPath As String, strFiles() As String, FileCount As Long)
Dim strDirs() As String
Dim strResult As String
Dim FileLimit As Long
Dim dirLimit As Long
Dim dirCount As Long
Dim I As Long
FileLimit = UBound(strFiles) + 1
dirLimit = 0
If Right$(strPath, 1) "/" Then strPath = strPath "/"
strResult = Dir(strPath, vbDirectory + vbSystem + vbReadOnly + vbHidden + vbNormal + vbArchive)
Do While Len(strResult) 0
If strResult "." And strResult ".." Then
If (GetAttr(strPath strResult) And vbDirectory) vbDirectory Then
If FileCount = FileLimit Then
ReDim Preserve strFiles(FileLimit + 10)
FileLimit = FileLimit + 10
End If
strFiles(FileCount) = strPath strResult
FileCount = FileCount + 1
Else
If dirCount = dirLimit Then
ReDim Preserve strDirs(dirLimit + 10)
dirLimit = dirLimit + 10
End If
strDirs(dirCount) = strPath strResult
dirCount = dirCount + 1
End If
End If
strResult = Dir(, vbDirectory + vbSystem + vbReadOnly + vbHidden + vbNormal + vbArchive)
Loop
For I = 0 To dirCount - 1
Call FindPath(strDirs(I), strFiles, FileCount)
Next I
End Sub
vb.net 如何用通配符查找文件
步骤如下:
窗体上添加2个列表框,一个按钮:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
'搜索并显示子文件夹
ListBox1.Items.Clear()
For Each MySubDir As String In System.IO.Directory.GetDirectories(MyDir)
ListBox1.Items.Add(MySubDir)
Next
'搜索并显示文件
ListBox2.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
ListBox2.Items.Add(MyFile)
Next
End Sub
End Class
VB.NET遍历查找某个文件夹,并找出指定文件
解压密码:1299
假设路径为C:\abc
代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Files As ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles("C:\abc")
Dim FileSize As Long, FileName As String = Nothing
Dim oFileSize As Long
For Each File As String In Files
oFileSize = My.Computer.FileSystem.GetFileInfo(File).Length
If oFileSize FileSize Then
FileSize = oFileSize
FileName = File
End If
Next
Dim ListN As ListViewItem = New ListViewItem(My.Computer.FileSystem.GetName(FileName))
ListN.SubItems.Add(oFileSize " byte")
ListN.SubItems.Add(My.Computer.FileSystem.GetFileInfo(FileName).Extension " 文件")
ListN.SubItems.Add(FileName)
ListView1.Items.Add(ListN)
End Sub
End Class
详见源代码!!
vb.net关键字搜索文件
窗体上添加一个文本框,一个列表框,一个按钮:
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
Dim MyFilter As String = "*" TextBox1.Text "*"
ListBox1.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir, MyFilter)
ListBox1.Items.Add(MyFile)
Next
End Sub
vb.net查找文件问题
思路:
1,使用ListBox1控件来存放搜索到的文件名,然后ListBox1.SelectedItem就可以返回选中项的文本;
2,利用获得的选中项文本(即文件与路径),使用打开文本文件的方法,读取内容显示在文本框里。
网站标题:vbnet查询文件,vbnet读取文件内容
网站路径:http://azwzsj.com/article/hejope.html