我在执行合并查询时遇到问题,以便将SELECT DISTINCT
[S].[TicketNbr] AS 'Ticket Nbr'
, [S].[status_description] AS 'Status'
, ( CASE WHEN [A].OldValue_Text = 'Service Desk' THEN 1 ELSE 0 END) AS 'Moved from Old Board?' END) AS 'Moved from Old Board?'
表中的值更新或插入 sql server数据库表。这是我的下面的代码,它没有给我任何错误或停止,但我最近注意到它已经在我的数据库表 dbo.schedule 中创建了完整的行,其中包含所有 NULL < / strong>即使是关键位置的价值,有人可以帮助我吗?我对sql中的合并查询不是很熟悉所以请指出我的语法问题:
DataGridView
答案 0 :(得分:1)
我想出来以防万一有人想知道,这是我的新代码:
Connexion.Open()
Dim query As String = String.Empty
Dim keypos = 0
query &= "UPDATE schedule SET Task = @Task, Complete = @Complete, Start_date = @Start_date, "
query &= "Due_date = @Due_date, JRID = @JRID, Task_Manager = @Task_Manager, Entered_By = @Entered_By, Time_Entered = @Time_Entered "
query &= "WHERE TaskID = @TaskID "
query &= "IF @@ROWCOUNT = 0 INSERT INTO schedule ( TaskID, Task, start_date, Due_Date, Complete, Task_Manager, JRID, Entered_By, Time_Entered)"
query &= " VALUES ( @TaskID, @Task, @start_date, @Due_Date, @Complete, @Task_Manager, @JRID, @Entered_By, @Time_Entered);"
For Each row As DataGridViewRow In MainSchedule.DataGridView1.Rows
If Not (row.Cells(0).Value = Nothing) Then
insertcommand.Parameters.Clear()
insertcommand.CommandText = query
insertcommand.Parameters.AddWithValue("@TaskID", row.Cells(0).Value)
insertcommand.Parameters.AddWithValue("@Complete", "False")
insertcommand.Parameters.AddWithValue("@Task", row.Cells(1).Value)
insertcommand.Parameters.AddWithValue("@Start_date", row.Cells(2).Value)
insertcommand.Parameters.AddWithValue("@Due_Date", row.Cells(3).Value)
insertcommand.Parameters.AddWithValue("@JRID", txtJRID.Text)
insertcommand.Parameters.AddWithValue("@Task_Manager", row.Cells(4).Value)
insertcommand.Parameters.AddWithValue("@Entered_By", GetUserName())
insertcommand.Parameters.AddWithValue("@Time_Entered", Now)
insertcommand.ExecuteNonQuery()
End If
keypos = keypos + 1
Next
Connexion.Close()