SQL y VB Otra forma cual seria
Publicado por Alex (1 intervención) el 07/08/2001 19:08:31
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim prm As ADODB.Parameter
Dim fld As ADODB.Field
Dim provStr As String
Dim cn As New ADODB.Connection
Private Sub Command1_Click()
' Connect using the SQLOLEDB provider.
cn.Provider = "sqloledb"
' Specify connection string on Open method.
provStr = "Server=ROPSASERVER;Database=master;Trusted_Connection=yes"
cn.Open provStr
' Set up a command object for the stored procedure.
Set cmd.ActiveConnection = cn
cmd.CommandText = "cliente"
cmd.CommandType = adCmdStoredProc
cmd.CommandTimeout = 15
' Set up a new parameter for the stored procedure.
Set prm = cmd.CreateParameter("busca", adWChar, adParamInput, 10, Text1)
cmd.Parameters.Append prm
' Create a recordset by executing the command.
Set rs = cmd.Execute
Set Flds = rs.Fields
' Print the values for all rows in the result set.
While (Not rs.EOF)
For Each fld In Flds
'Text2 = rs.Fields("IDcliente")
Text2 = rs.Fields("Compañia")
Text3 = rs.Fields("Rfc")
Text4 = rs.Fields("Calle")
Text5 = rs.Fields("Entre_calle")
Text6 = rs.Fields("y_calle")
' Text2 = "" & fld.Value
Next
Debug.Print ""
rs.MoveNext
Wend
' Close recordset and connection.
rs.Close
cn.Close
End Sub
Dim rs As New ADODB.Recordset
Dim prm As ADODB.Parameter
Dim fld As ADODB.Field
Dim provStr As String
Dim cn As New ADODB.Connection
Private Sub Command1_Click()
' Connect using the SQLOLEDB provider.
cn.Provider = "sqloledb"
' Specify connection string on Open method.
provStr = "Server=ROPSASERVER;Database=master;Trusted_Connection=yes"
cn.Open provStr
' Set up a command object for the stored procedure.
Set cmd.ActiveConnection = cn
cmd.CommandText = "cliente"
cmd.CommandType = adCmdStoredProc
cmd.CommandTimeout = 15
' Set up a new parameter for the stored procedure.
Set prm = cmd.CreateParameter("busca", adWChar, adParamInput, 10, Text1)
cmd.Parameters.Append prm
' Create a recordset by executing the command.
Set rs = cmd.Execute
Set Flds = rs.Fields
' Print the values for all rows in the result set.
While (Not rs.EOF)
For Each fld In Flds
'Text2 = rs.Fields("IDcliente")
Text2 = rs.Fields("Compañia")
Text3 = rs.Fields("Rfc")
Text4 = rs.Fields("Calle")
Text5 = rs.Fields("Entre_calle")
Text6 = rs.Fields("y_calle")
' Text2 = "" & fld.Value
Next
Debug.Print ""
rs.MoveNext
Wend
' Close recordset and connection.
rs.Close
cn.Close
End Sub
Valora esta pregunta


0