Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在视图列表中选择数据_Vb.net_Ms Access - Fatal编程技术网

Vb.net 在视图列表中选择数据

Vb.net 在视图列表中选择数据,vb.net,ms-access,Vb.net,Ms Access,我想请你帮个忙。我使用viewlist在访问vb.net时显示数据,但如果我想选择一个名称,则不能。你能帮我吗?已进行编码,但我不知道故障在哪里 Imports System.Data.OleDb Imports System.Data Public Class Guest_List Dim cnn As OleDbConnection Dim cmmd As OleDbCommand Dim dReader As OleDbDataReader Public t

我想请你帮个忙。我使用viewlist在访问vb.net时显示数据,但如果我想选择一个名称,则不能。你能帮我吗?已进行编码,但我不知道故障在哪里

Imports System.Data.OleDb
Imports System.Data
Public Class Guest_List
    Dim cnn As OleDbConnection
    Dim cmmd As OleDbCommand
    Dim dReader As OleDbDataReader
    Public title, FirstName, LastName, Address, Country, Company, DateIn, DateOut, RoomType, Note As String
    Private Sub Guest_List_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call list_data()
    End Sub

    Private Sub txtKataKunci_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKataKunci.TextChanged
        Call list_data()
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        Call pilih()
    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Call pilih()
    End Sub

    Private Sub list_data()

        Call clear_list()
        Dim sqlx As String
        Dim x As Integer

        sqlx = "select title,firstname,lastname,address,country,company,datein,dateout,roomtype,notes from tcekin where firstname like '%" & Trim(txtKataKunci.Text) & "%' order by firstname  asc"

        cnn = New OleDbConnection(strConn)
        If cnn.State <> ConnectionState.Closed Then cnn.Close()
        cnn.Open()
        cmmd = New OleDbCommand(sqlx, cnn)
        dReader = cmmd.ExecuteReader

        Try
            While dReader.Read = True
                x = Val(counter.Text)
                counter.Text = Str(Val(counter.Text) + 1)

                With ListView1
                    .Items.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(x).SubItems(0).Text = dReader.GetString(0)
                    .Items(x).SubItems(1).Text = dReader.GetString(1)
                    .Items(x).SubItems(2).Text = dReader.GetString(2)
                    .Items(x).SubItems(3).Text = dReader.GetString(3)
                    .Items(x).SubItems(4).Text = dReader.GetString(4)
                    .Items(x).SubItems(5).Text = dReader.GetString(5)
                    .Items(x).SubItems(6).Text = Format(CDate(dReader.GetDateTime(6)), "dd-MMMM-yyyy")
                    .Items(x).SubItems(7).Text = Format(CDate(dReader.GetDateTime(7)), "dd-MMMM-yyyy")
                    .Items(x).SubItems(8).Text = dReader.GetString(8)
                    .Items(x).SubItems(9).Text = dReader.GetString(9)
                End With
            End While
        Finally
            dReader.Close()
        End Try
        cnn.Close()
    End Sub

    Private Sub clear_list()
        While Val(counter.Text) > 0
            ListView1.Items(0).Remove()
            counter.Text = Val(counter.Text) - 1
        End While
    End Sub

    Private Sub pilih()
        Try
            title = ListView1.SelectedItems(0).SubItems(0).Text.ToString
            FirstName = ListView1.SelectedItems(0).SubItems(1).Text.ToString
            LastName = ListView1.SelectedItems(0).SubItems(2).Text.ToString
            Address = ListView1.SelectedItems(0).SubItems(3).Text.ToString
            Country = ListView1.SelectedItems(0).SubItems(4).Text.ToString
            Company = ListView1.SelectedItems(0).SubItems(5).Text.ToString
            DateIn = ListView1.SelectedItems(0).SubItems(6).Text.ToString
            DateOut = ListView1.SelectedItems(0).SubItems(7).Text.ToString
            RoomType = ListView1.SelectedItems(0).SubItems(8).Text.ToString
            Note = ListView1.SelectedItems(0).SubItems(9).Text.ToString
            Me.Close()
        Catch ex As Exception
            MsgBox("pilih salah satu data", MsgBoxStyle.Information)
        End Try

    End Sub
End Class
导入System.Data.OleDb
导入系统数据
公务舱客人名单
将cnn设置为OLEDB连接
作为OLEDB命令的Dim cmmd
作为OLEDB数据读取器的暗淡恐惧
公共标题、名字、姓氏、地址、国家、公司、日期输入、日期输出、房间类型、注释为字符串
Private Sub Guest_List_Load(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
呼叫列表_数据()
端接头
私有子txtkatakuni_TextChanged(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理txtkatakuni.TextChanged
呼叫列表_数据()
端接头
私有子ListView1\u SelectedIndexChanged(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理ListView1.SelectedIndexChanged
调用pilih()
端接头
私有子btnOk_Click(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理btnOk。单击
调用pilih()
端接头
私有子列表_数据()
调用清除列表()
将sqlx设置为字符串
作为整数的Dim x
sqlx=“选择标题、名字、姓氏、地址、国家/地区、公司、日期输入、日期输出、房间类型、来自tcekin的注释,其中名字如“%”和Trim(txtkatakunc.Text)和“%”按姓氏排序asc”
cnn=新的OLEDB连接(strConn)
如果cnn.State ConnectionState.Closed,那么cnn.Close()
cnn.Open()
cmmd=新的OleDbCommand(sqlx,cnn)
恐惧者=cmmd.ExecuteReader
尝试
而dReader.Read=True
x=Val(counter.Text)
counter.Text=Str(Val(counter.Text)+1)
使用ListView1
.项目。添加(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(ListView1.Items.Count-1).SubItems.Add(“”)
.Items(x).SubItems(0).Text=dReader.GetString(0)
.Items(x).SubItems(1).Text=dReader.GetString(1)
.Items(x).子项(2).Text=dReader.GetString(2)
.Items(x).子项(3).Text=dReader.GetString(3)
.Items(x).子项(4).Text=dReader.GetString(4)
.Items(x).子项(5).Text=dReader.GetString(5)
.Items(x).SubItems(6).Text=格式(CDate(dReader.GetDateTime(6)),“dd-MMMM-yyyy”)
.Items(x).SubItems(7).Text=格式(CDate(dReader.GetDateTime(7)),“dd-MMMM-yyyy”)
.Items(x).子项(8).Text=dReader.GetString(8)
.Items(x).SubItems(9).Text=dReader.GetString(9)
以
结束时
最后
恐怖分子
结束尝试
cnn.Close()
端接头
专用子清除列表()
而Val(counter.Text)>0
ListView1.Items(0).Remove()
counter.Text=Val(counter.Text)-1
结束时
端接头
私人分队()
尝试
title=ListView1.SelectedItems(0).子项(0).Text.ToString
FirstName=ListView1.SelectedItems(0).子项(1).文本.ToString
LastName=ListView1.SelectedItems(0).子项(2).文本.ToString
Address=ListView1。SelectedItems(0)。子项(3)。Text.ToString
Country=ListView1.选择编辑项(0).子项(4).文本.ToString
Company=ListView1。选择EditEMS(0)。子项(5)。Text.ToString
DateIn=ListView1.SelectedItems(0).子项(6).文本.ToString
DateOut=ListView1.SelectedItems(0).子项(7).Text.ToString
RoomType=ListView1.SelectedItems(0).子项(8).Text.ToString
注意=列表视图1。选择编辑项(0)。子项(9)。Text.ToString
我
特例
MsgBox(“pilih salah satu数据”,MsgBoxStyle.Information)
结束尝试
端接头
末级
你说的“选择一个名字”是什么意思?您正在尝试从数据库中查询特定名称吗

将sqlx更改为

String.Format("select title,firstname,lastname,address,country,company,datein,dateout,roomtype,notes from tcekin where firstname like '%{0}%' order by firstname  asc", txtKataKunci.Text.Trim())

然后在读卡器上添加一个断点,点击F5,查看是否有数据从数据库返回。您还可以尝试直接在access db上运行查询。

尝试使用

这样,sql语句将返回所有记录