简体   繁体   English

使用asp.net(VB)从MySQL中选择,更新,插入和删除的脚本?

[英]Script to select, update, insert and delete from MySQL with asp.net (VB)?

I've just switched from classic ASP to .net and I always used the following to SELECT, INSERT, UPDATE and DELETE from my MySQL databases: 我刚刚从经典ASP切换到.net,我总是使用以下来从我的MySQL数据库中选择SELECT,INSERT,UPDATE和DELETE:

' Create db connection
Function dbConn()
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open "driver=x;Server=x;Port=x;Option=x;Database=x;Uid=x;Pwd=x"
    Set dbConn = objConn
End Function

' Store data in array
Function SQL(myCommand,strSQL)
    Set objConn = dbConn()
    If myCommand = 0 Then
        Set objRS = objConn.Execute(strSQL)
        If NOT objRS.EOF Then arrRS = objRS.GetRows Else arrRS = Null
    Else
        Set objRS = objConn.Execute(strSQL,,128)
    End If
    Set objRS = Nothing : Set objConn = Nothing
End Function

For example, to use SELECT I'd just go: 例如,使用SELECT我只是去:

Call SQL(0,"SELECT * FROM Users")

And to display the data: 并显示数据:

If IsArray(arrRS) Then
    For i = 0 to UBound(arrRS,2)
        Response.Write(arrRS(0,i) & ", " & arrRS(1,i))
    Next
End If

And to insert, update or delete I'd use: 并插入,更新或删除我使用:

Call SQL(1,"DELETE FROM Users WHERE UserID = 1")

Does anyone know if this is possible with ASP.Net - VB? 有没有人知道这是否可以使用ASP.Net - VB? Or is there an even handier solution? 或者是否有更方便的解决方案?

Cheers. 干杯。

Yes, you can certainly do that with VB.NET. 是的,你当然可以用VB.NET做到这一点。 VB.NET supports almost everything ASP classic and vbscript could do. VB.NET几乎支持ASP classic和vbscript所能做的一切。 ADO.NET supports almost everything ADO did. ADO.NET几乎支持ADO所做的一切。

... not that you'd want to do it. ......不是你想要这样做。

I strongly suggest that you look into the pattern and practices that ASP.NET allows. 我强烈建议您研究ASP.NET允许的模式和实践。 The newer methods are much better than the old ones. 较新的方法比旧方法好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM