|
'' 建立查询字符串,可以支持模糊查询 OleDbCommand1 = New OleDbCommand Me.OleDbCommand1.CommandText = selstring Me.OleDbCommand1.Connection = OleDbConnection1 ''以下几句是显示匹配的条数 DataSet1 = New DataSet OleDbDataAdapter1 = New OleDbDataAdapter(selstring, OleDbConnection1) OleDbDataAdapter1.Fill(DataSet1, "users") ListBox1.Items.Add("共有" &DataSet1.Tables("users").Rows.Count &"条匹配的记录") ListBox1.Items.Add("-------------------------------------------------------------") Try ''进行异常处理 Dim cmdreader As OleDbDataReader = OleDbCommand1.ExecuteReader() While cmdreader.Read ''注意这里要用while ''不然就无法进行循环,就只能进行一次查询 ListBox1.Items.Add(cmdreader("nameid").ToString()) ListBox1.Items.Add(cmdreader("age").ToString()) ListBox1.Items.Add(cmdreader("faverity").ToString()) ListBox1.Items.Add("----------------------------------") End While cmdreader.Close() OleDbConnection1.Close() Catch ex As Exception ListBox1.Items.Add("Errors") End Try Else End If //================再把来XML文档,以XML形式显示在ListBox里面 双击"XML文档" 写进下面这些代码: ListBox1.Items.Clear() '' 清空listBox Dim xtr As XmlTextReader = New XmlTextReader("myxml.xml") ''创建成一个XmlTextReader读取"myxml.xml"文档 While xtr.Read Select Case (xtr.NodeType) '' 咱们用select case 形式来选择xml节点类型 Case XmlNodeType.XmlDeclaration ''先从ListBox里写进xml声明=====xmldeclaration ListBox1.Items.Add("") ''再依次显示节点的名称,值 ''包括根节点 Case XmlNodeType.Element ListBox1.Items.Add("<" &xtr.Name &">") |