我使用SqlDataSource
代码来更新数据
UPDATE [centreadmin]
SET [centreadmin].centre = [centre].centre
FROM [centre], [centreadmin]
WHERE [centreadmin].centre = [centre].oldcentre
但现在我不想使用SqlDataSource
。
我在.vb中试过但没有成功。
Protected Sub BtnUpdateAdmin_Click(sender As Object, e As EventArgs) Handles BtnUpdateAdmin.Click
Dim connection As New SqlConnection()
connection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim comd = connection.CreateCommand()
connection.Open()
comd.CommandText = "UPDATE [centreadmin] SET [centreadmin].centre = [centre].centre FROM [centre], [centreadmin] WHERE [centreadmin].centre = [centre].oldcentre"
connection.Close()
End Sub
End Class
我做错了什么,我怎样才能做到这一点?
答案 0 :(得分:0)
您永远不会执行SQL。在其中加入ExecuteNonQuery (MSDN):
...
connection.Open()
comd.CommandText = "UPDATE [centreadmin] SET [centreadmin].centre = [centre].centre FROM [centre], [centreadmin] WHERE [centreadmin].centre = [centre].oldcentre"
comd.ExecuteNonQuery()
connection.Close()
...
答案 1 :(得分:0)