我正在将vb6转换为.net。我需要将其转换为.net。我可以用dbdccommand吗?
Public Const CN As String = "Driver={SQL Server};Server=TESTDB;Database=DBA;User Id=DBO;PassWord=dbotest;"
cmd = New ADODB.Command
rs = New ADODB.Recordset
With cmd
.let_ActiveConnection(CN)
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandText = "s_Servers"
rs = cmd.Execute
End With
答案 0 :(得分:0)
您应该使用ADO.NET。
以下是一些有用的链接:
http://msdn.microsoft.com/en-us/library/ms971478.aspx
http://quickstart.developerfusion.co.uk/quickstart/howto/doc/adoplus/employees.aspx
答案 1 :(得分:0)
Using cnn as New SqlCommand("Driver={SQL Server};Server=TESTDB;Database=DBA;User Id=DBO;PassWord=dbotest;")
cnn.Open
Using cmd as SQLCommand = cnn.CreateCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "s_Servers"
Using da as New SQLDataAdapter
da.SelectCommand = cmd
Using ds as New DataSet
da.fill(ds)
' here's where you figure out how to work with a dataset
' you can take it from here
End Using
End Using
End Using
End Using
答案 2 :(得分:0)
我找到了办法。
Dim serverNm As Object
Using connection As New SqlConnection(CN)
Dim command As New SqlCommand
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
command.CommandText = "s_Servers"
connection.Open()
Using readerObj As SqlClient.SqlDataReader = command.ExecuteReader()
While readerObj.Read
serverNm = readerObj("ServerNm")
End While
End Using
connection.Close()
End Using