将相同的值插入列中

时间:2018-03-09 11:46:54

标签: sql vb.net

我有一个代码,用于将折线的每个点的坐标保存到Access数据库。我保存这些坐标的表由6列组成:ID,ENT_ID,ORDER_NUM,X,Y,Z。每个点都有一个ORDER_NUM。当我用5点ORDER_NUM星形创建0到4的折线时(它只是点的计数器)。但我需要SQL在一条折线内用相同的值填充ENT_ID。例如,我有5个点的折线,并且每个点ENT_ID应该相同。当我绘制新的折线时,ENT_ID应该增加1并重新增加。有什么建议吗?

# define matrix
m <- matrix(c(0,0,1,1,0,1,1,1,0),nrow = 3, ncol = 3)

# define gender vector
gender <- c("male", "female", "male")

# find: male-male friendships
mm <- subset.matrix(m, subset = gender == "male", select = gender == "male")
sum(mm)/(dim(mm)[1]*dim(mm)[2])

1 个答案:

答案 0 :(得分:0)

如果你可以为你的折线输入一个Point数组,那么你可以循环遍历它们,递增索引并在每个循环中插入一条记录。我猜你有自己的Point结构/类,所以我添加了一个,所以我的代码会编译。

Private Sub EnterPolyline(EntId As Integer, myPoints() As Point)
        Dim myconnection As New OleDbConnection("Connection String")
        Dim sqlQryPolyline As String = "INSERT INTO Polylinepoints (ENT_ID, ORDER_NUM, X, Y, Z) VALUES (pENT_ID, pORDER_NUM , pX, pY, pZ)"

        Using cmd As New OleDbCommand(sqlQryPolyline, myconnection)
            Dim pointIndex As Integer = 0
            For Each aPoint In myPoints
                Dim poinIndex As Integer = 0
                cmd.Parameters.AddWithValue("pENT_ID", EntId)
                cmd.Parameters.AddWithValue("pORDER_NUM", pointIndex)
                cmd.Parameters.AddWithValue("pX", aPoint.X)
                cmd.Parameters.AddWithValue("pY", aPoint.y)
                cmd.Parameters.AddWithValue("pZ", aPoint.Z)
                cmd.ExecuteNonQuery()
                pointIndex += 1
            Next
        End Using
End Sub
Public Structure Point
        Public X As Integer
        Public y As Integer
        Public Z As Integer
End Structure