【发布时间】:2021-02-02 18:55:18
【问题描述】:
我有一个网格,其 (x,y) 坐标对应于 SQL Server。 每个坐标没有一行;只有那些不是空白的。有一列(“填充”)存储这些颜色代码整数。
当应用程序加载时,我在下面有一个序列循环遍历网格高度/宽度内的每个 (X,Y) 坐标。在这个循环中,它询问所讨论的 (X,Y) 是否与行中的匹配,如果返回 TRUE,则根据保存在行中的整数更新 Fill 整数。如果这返回 FALSE,我将行增加一并再次查看,直到它查看了保存在表中的每一行(名为 SQL.RecordCount)。完成此操作后,我增加 X(向右移动到下一个单元格)并再次执行此过程;一旦我到达行的末尾(其中 X = MapWidth),我就会转到下一行的开头并再次前进。如此重复直到 Y = MapHeight,如下面的代码所示。
对我来说,这个顺序是有道理的,所以肯定有一些我不知道的东西丢失了。即使您没有确切的解决方案,也非常感谢任何能够推动这个僵局的东西。
基于 cmets 的编辑在双星号中:
Public Sub LoadMap()
Dim Fill As Integer = 0
Dim Row As Integer = 0
Dim X As Integer = 0
Dim Y As Integer = 0
SQL.ExecQuery("SELECT * FROM Mapper_Table")
Do While Y <= MapHeight
'Ultimate exit statement: stop loading cells when Y becomes greater than the MapHeight...
Do While X <= MapWidth
'Row Exit Statement: When X reaches 100, its time to start on the next row...
Do While Row < SQL.RecordCount '12
'I only want to search as many rows as there are saved locations, otherwise the cell must be empty and therefore blank...
If X = SQL.DBDT.Rows(Row).Item("X") And Y = SQL.DBDT.Rows(Row).Item("Y") Then
'If the current (X,Y) is a match to the database row, then we take the stored colour...
Fill = SQL.DBDT.Rows(Row).Item("Fill")
End If
'If Fill is taken, we can colour the square; otherwise, we should look in the next row...
If Fill <> 0 Then
Map(X, Y, 0) = Fill
End If
** Row = Row + 1 **
Loop
'Once we have looked in all the rows for out cell, it is either coloured in or not; we can move onto the next cell in the row; a.k.a...
X = X + 1
** Fill = 0 **
Loop
'Once we have looked for all the cells in our row, we can move onto the next one; a.k.a...
X = 0
Y = Y + 1
Loop
'Once we get to the end of the map, it should be loaded!
End Sub
【问题讨论】:
-
好的,谢谢。我是在做你说的吗?先查询所有数据,然后让序列运行它?
-
这个
SQL对象是什么?它是如何工作的?为什么不直接使用 ADO.NET(SqlConnection、SqlCommand和SqlDataReader?) -
所以 SQL 引用了我的 SQL 控件类。我会在上面更新...
-
为什么要为网格上的每个 X 和 Y 坐标探测结果集?为什么不只遍历结果集并使用它包含的 X、Y、Fill 值?
-
首先 - 循环有什么问题?它永远消失了吗?我不是 100%,但如果
FILL有一个值,那么Do While Row < SQL.RecordCount循环将永远存在?
标签: sql-server vb.net visual-studio