任何人都可以帮我处理我的代码,它会在代码片段的最后一行出现错误并出现错误:附加信息:除非指定了DeleteCommand,否则数据源不支持删除。
Dim ds As New SqlDataSource(sConnectionString, "DELETE FROM dbo.NUVIDA_LT_ASSESSMENTS WHERE ASSESSMENTS_ID = @ASSESSMENTS_ID")
ds.DeleteParameters.Add("ASSESSMENT_ID", ASSESSMENT_ID)
Dim x As Integer = ds.Delete()
答案 0 :(得分:1)
您将删除语句传递给SqlDataSource对象的SELECT语句。所以它抛出删除命令不支持。
为什么不使用SqlCommand和ExecuteNonQuery方法?
Using connection As New SqlConnection(sConnectionString)
Dim myDelCommand As New SqlCommand("DELETE FROM dbo.NUVIDA_LT_ASSESSMENTS WHERE ASSESSMENTS_ID = @ASSESSMENTS_ID", connection)
myDelCommand.Parameters.Add("@ASSESSMENTS_ID", SqlDbType.Int)
myDelCommand.Parameters("@ASSESSMENTS_ID").Value = 123
myDelCommand.Connection.Open()
myDelCommand.ExecuteNonQuery()
End Using