...

View Full Version : problem with vb ADO



mad_girl
08-25-2007, 08:01 PM
hey experts, need some help here
the prob is this is my first time using visual basic and ADO so i got some errors in my codes which i can't work out
i'm sending the code now and i hope u tell me what i did wrong
__________________________________________________ ________
Dim adoConn As ADODB.Connection
Dim cmd As ADODB.Command
Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

End Sub

Private Sub addUser_Click()
Dim nou As Integer
cmd = New ADODB.Command
cmd.ActiveConnection = adoConn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "info"
cmd.Parameters.Append cmd.CreateParameter("id", adInteger, adParamInput, Val(refId.Text))
cmd.Parameters.Append cmd.CreateParameter("numOfUsers", adInteger, adParamOutput)
cmd.Execute
nou = cmd("numOfUsers")
If (nou = 3) Then
MsgBox "sorry,can't add more than 3 users under one referrer"
End If

End Sub

Private Sub Form_Load()
Dim constr As String
adoConn = New ADODB.Connection
adoConn.Provider = "SQLOLEDB.1"
adoConn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=new;Data Source=np:MOHAMMED\SQLEXPRESS;Initial File Name=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\nEw.mdf"
adoConn.Open

End Sub

PremiumBlend
08-25-2007, 08:11 PM
Have you defined the variable "adCmdStoredProc"?

cmd.CommandType expects an integer.

mad_girl
08-25-2007, 08:15 PM
but adCmdStoredProc is a built in value:confused:

oracleguy
08-25-2007, 08:19 PM
Could you post what errors you are getting?

PremiumBlend
08-25-2007, 08:21 PM
I've had problems with this too. I've seen things where it is built in but I've found that implementation to be confusing. Have you tried just coding the value directly?

Here is a link to the values (http://www.w3schools.com/ado/prop_comm_commandtype.asp#commandtypeenum)

mad_girl
08-25-2007, 08:25 PM
ok i'm getting an error on each line of this code:
adoConn = New ADODB.Connection
adoConn.Provider = "SQLOLEDB.1"
adoConn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=new;Data Source=np:MOHAMMED\SQLEXPRESS;Initial File Name=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\nEw.mdf"
adoConn.Open

//object variable or with block variable not set
i put the declaration of adoConn in general declarations

cmd.ActiveConnection = adoConn
//object doesn't support method or property

mad_girl
08-25-2007, 08:26 PM
PremiumBlend:
no actually i don know what values correspond to this property

oracleguy
08-25-2007, 09:00 PM
try doing:


set adoConn = New ADODB.Connection

That might clear up the first error message.

mad_girl
08-25-2007, 09:11 PM
i did that but i had new error
Set adoConn.Provider="SQLOLEDB.1"
//invalid use of property
i knooow beginners are annoying

oracleguy
08-25-2007, 09:43 PM
On that liine get rid of the 'set'.

mad_girl
08-25-2007, 09:58 PM
thank u sooo much this part worked and the connection came alive
hoping there would be no errors in the other parts



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum