Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.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
SQL语句作为listbox VB.NET的数据源_Sql_Database_Vb.net_Listbox - Fatal编程技术网

SQL语句作为listbox VB.NET的数据源

SQL语句作为listbox VB.NET的数据源,sql,database,vb.net,listbox,Sql,Database,Vb.net,Listbox,好的,我得到了一个列表框,我将displaymember设置为“ID” 我填充数据集,如果我对数据集进行更改,列表框也会更改 我正在用这种数据适配器填充数据集: KamersDataAdapter=newSQLDataAdapter(“从roomsTable中选择ID”,ConnectionString) 到目前为止还不错 如果我能写一个漂亮的句子,这样用户就可以在列表框中读到一些漂亮的东西,然后只读数据库项,那就太酷了。所以我这样做了: New SqlDataAdapter("SELECT *

好的,我得到了一个列表框,我将displaymember设置为“ID”

我填充数据集,如果我对数据集进行更改,列表框也会更改

我正在用这种数据适配器填充数据集:

KamersDataAdapter=newSQLDataAdapter(“从roomsTable中选择ID”,ConnectionString)

到目前为止还不错

如果我能写一个漂亮的句子,这样用户就可以在列表框中读到一些漂亮的东西,然后只读数据库项,那就太酷了。所以我这样做了:

New SqlDataAdapter("SELECT *, convert(varchar,convert(date,StartDatum),103) +' - ' + convert(varchar,convert(date,EindDatum),103) + ': room ' + convert(varchar,KamerNummer) AS combinatie FROM VerhuringenTable", ConnectionString)
然后,我没有将displaymember放在ID中,而是将其放在Combinatie中(荷兰语表示combination)

现在,如果我第一次填充数据集,一切都会好起来。然后我得到这个:

18/01/2014-30/05/2014:room 103
但现在当我添加一个新房间时。这个房间不想出现在我的列表框中。 换句话说,我的数据集没有更新,或者我的列表框无法处理此查询

我知道这与这个sql语句有关,因为当我只选择ID时,我的列表框会很好地更新

有人知道发生了什么事吗

塔克斯


fosa

从数据库中提取数据时计算列的组合。在此之后,数据集不包含任何可在运行时应用的规则,以从新文件室的数据生成
combinatie
列。 您应该手动将此字段的信息添加到数据集表中,
可能是在您添加房间预订时

 Dim newRow = ds.Tables("room").NewRow()
 newRow("StartDatum") = DateTime.Today
 newRow("EindDatum") = DateTime.Today.AddDays(7)
 newRow("KamerNummer") = roomNumber
 ....
 newRow("combinatie") = DateTime.Today.ToShortDateString() & "-" & _ 
                        DateTime.Today.AddDays(7).ToShortDateString() & _ 
                        ":room " & roomNumber.ToString()
ds.Tables("room").Rows.Add(newRow)

将项添加到数据库,然后重新运行查询。我不希望数据库中有数据。我希望它在我的数据集中。当我最终将数据库与数据集同步时,我希望数据库中的数据……这是一个不同的按钮课程!我怎么会这么笨。萃取后确实建立了柱组合。数据集什么都不知道…Thanx Steve!