|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Missing operandDim authCommand As String = "select count(*) as iRowCount
from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate > getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" Dim oleCommand As New OleDbCommand(authCommand, authConnection) oleCommand.Parameters.Add(New OleDbParameter("@cocode", OleDbType.VarChar, 10)) oleCommand.Parameters("@cocode").Value = UserName oleCommand.Parameters.Add(New OleDbParameter("@pwd", OleDbType.VarChar, 50)) oleCommand.Parameters("@pwd").Value = UserPassword Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), Integer) <--- error It said "Missing operand" . Please help Well, you shouldn't need to CType the ExcecuteScalar function call because
ExcecuteScalar returns an integer anyway. But, if your command being executed causes an exception, ExcecuteScalar may be the root of that. Put your code in a Try...Catch and see if (and by stepping the code) and where an exception is occuring. Show quoteHide quote "Agnes" <ag***@dynamictech.com.hk> wrote in message news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... > Dim authCommand As String = "select count(*) as iRowCount > from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate > > getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" > Dim oleCommand As New OleDbCommand(authCommand, > authConnection) > > oleCommand.Parameters.Add(New OleDbParameter("@cocode", > OleDbType.VarChar, 10)) > oleCommand.Parameters("@cocode").Value = UserName > oleCommand.Parameters.Add(New OleDbParameter("@pwd", > OleDbType.VarChar, 50)) > oleCommand.Parameters("@pwd").Value = UserPassword > > Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), > Integer) <--- error > It said "Missing operand" . Please help > > Hello Scott M.,
Just a quick point.. .ExecuteScalar returns an Object, not an Integer. .ExecuteNonQuery returns an Integer. -Boo Show quoteHide quote > Well, you shouldn't need to CType the ExcecuteScalar function call > because ExcecuteScalar returns an integer anyway. But, if your command > being executed causes an exception, ExcecuteScalar may be the root of > that. > > Put your code in a Try...Catch and see if (and by stepping the code) > and where an exception is occuring. > > "Agnes" <ag***@dynamictech.com.hk> wrote in message > news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... > >> Dim authCommand As String = "select count(*) as iRowCount >> from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate >> > >> getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" >> Dim oleCommand As New OleDbCommand(authCommand, >> authConnection) >> oleCommand.Parameters.Add(New OleDbParameter("@cocode", >> OleDbType.VarChar, 10)) oleCommand.Parameters("@cocode").Value = >> UserName oleCommand.Parameters.Add(New OleDbParameter("@pwd", >> OleDbType.VarChar, 50)) oleCommand.Parameters("@pwd").Value = >> UserPassword >> >> Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), >> Integer) <--- error >> It said "Missing operand" . Please help Oops! My bad, you are right.
Show quoteHide quote "GhostInAK" <ghosti***@gmail.com> wrote in message news:be1391bf15a428c898bdf9e36086@news.microsoft.com... > Hello Scott M., > > Just a quick point.. .ExecuteScalar returns an Object, not an Integer. > .ExecuteNonQuery returns an Integer. > > -Boo > >> Well, you shouldn't need to CType the ExcecuteScalar function call >> because ExcecuteScalar returns an integer anyway. But, if your command >> being executed causes an exception, ExcecuteScalar may be the root of >> that. >> >> Put your code in a Try...Catch and see if (and by stepping the code) >> and where an exception is occuring. >> >> "Agnes" <ag***@dynamictech.com.hk> wrote in message >> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... >> >>> Dim authCommand As String = "select count(*) as iRowCount >>> from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate >>> > >>> getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" >>> Dim oleCommand As New OleDbCommand(authCommand, >>> authConnection) >>> oleCommand.Parameters.Add(New OleDbParameter("@cocode", >>> OleDbType.VarChar, 10)) oleCommand.Parameters("@cocode").Value = >>> UserName oleCommand.Parameters.Add(New OleDbParameter("@pwd", >>> OleDbType.VarChar, 50)) oleCommand.Parameters("@pwd").Value = >>> UserPassword >>> >>> Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), >>> Integer) <--- error >>> It said "Missing operand" . Please help > > Agnes,
The OleDBcommand does AFAIK not use named parameters, therefore are it 3 paremeters, you are offering however only 2. Change the names as @Code just for ?, than you will see it mabye better. The documentation about this is not always well on MSDN, it is changed, but the old ones are not deleted. Cor Show quoteHide quote "Agnes" <ag***@dynamictech.com.hk> schreef in bericht news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... > Dim authCommand As String = "select count(*) as iRowCount > from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate > > getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" > Dim oleCommand As New OleDbCommand(authCommand, > authConnection) > > oleCommand.Parameters.Add(New OleDbParameter("@cocode", > OleDbType.VarChar, 10)) > oleCommand.Parameters("@cocode").Value = UserName > oleCommand.Parameters.Add(New OleDbParameter("@pwd", > OleDbType.VarChar, 50)) > oleCommand.Parameters("@pwd").Value = UserPassword > > Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), > Integer) <--- error > It said "Missing operand" . Please help > > Yes Cor, oleDBCommand *can* work with named parameters, but the names must
be in the same order as the parameters are in the parameters collection of the command itself. Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl... > Agnes, > > The OleDBcommand does AFAIK not use named parameters, therefore are it 3 > paremeters, you are offering however only 2. Change the names as @Code > just for ?, than you will see it mabye better. > > The documentation about this is not always well on MSDN, it is changed, > but the old ones are not deleted. > > Cor > > "Agnes" <ag***@dynamictech.com.hk> schreef in bericht > news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... >> Dim authCommand As String = "select count(*) as iRowCount >> from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate > >> getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" >> Dim oleCommand As New OleDbCommand(authCommand, >> authConnection) >> >> oleCommand.Parameters.Add(New OleDbParameter("@cocode", >> OleDbType.VarChar, 10)) >> oleCommand.Parameters("@cocode").Value = UserName >> oleCommand.Parameters.Add(New OleDbParameter("@pwd", >> OleDbType.VarChar, 50)) >> oleCommand.Parameters("@pwd").Value = UserPassword >> >> Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), >> Integer) <--- error >> It said "Missing operand" . Please help >> >> > > Scott,
I know that you can use them, but in OleDB you can set everything you want in that place, even a question mark. In the parameters you can than set a simple "" or whatever you want. Cor Show quoteHide quote "Scott M." <s-mar@nospam.nospam> schreef in bericht news:OysK5QfyGHA.4972@TK2MSFTNGP03.phx.gbl... > Yes Cor, oleDBCommand *can* work with named parameters, but the names must > be in the same order as the parameters are in the parameters collection of > the command itself. > > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message > news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl... >> Agnes, >> >> The OleDBcommand does AFAIK not use named parameters, therefore are it 3 >> paremeters, you are offering however only 2. Change the names as @Code >> just for ?, than you will see it mabye better. >> >> The documentation about this is not always well on MSDN, it is changed, >> but the old ones are not deleted. >> >> Cor >> >> "Agnes" <ag***@dynamictech.com.hk> schreef in bericht >> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... >>> Dim authCommand As String = "select count(*) as iRowCount >>> from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate > >>> getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" >>> Dim oleCommand As New OleDbCommand(authCommand, >>> authConnection) >>> >>> oleCommand.Parameters.Add(New OleDbParameter("@cocode", >>> OleDbType.VarChar, 10)) >>> oleCommand.Parameters("@cocode").Value = UserName >>> oleCommand.Parameters.Add(New OleDbParameter("@pwd", >>> OleDbType.VarChar, 50)) >>> oleCommand.Parameters("@pwd").Value = UserPassword >>> >>> Dim iCount As Integer = CType(oleCommand.ExecuteScalar(), >>> Integer) <--- error >>> It said "Missing operand" . Please help >>> >>> >> >> > > You can create a parameter and set all of its properties (OleDbType, Name,
Length, Precision, etc.) and all of these will be enforced come ExecuteCommand time. The actual name @something referenced in the CommandText is ignored though. Only the amount and order of the parameters are what is used. Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%23ruohsfyGHA.4044@TK2MSFTNGP04.phx.gbl... > Scott, > > I know that you can use them, but in OleDB you can set everything you want > in that place, even a question mark. In the parameters you can than set a > simple "" or whatever you want. > > Cor > > "Scott M." <s-mar@nospam.nospam> schreef in bericht > news:OysK5QfyGHA.4972@TK2MSFTNGP03.phx.gbl... >> Yes Cor, oleDBCommand *can* work with named parameters, but the names >> must be in the same order as the parameters are in the parameters >> collection of the command itself. >> >> >> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message >> news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl... >>> Agnes, >>> >>> The OleDBcommand does AFAIK not use named parameters, therefore are it 3 >>> paremeters, you are offering however only 2. Change the names as @Code >>> just for ?, than you will see it mabye better. >>> >>> The documentation about this is not always well on MSDN, it is changed, >>> but the old ones are not deleted. >>> >>> Cor >>> >>> "Agnes" <ag***@dynamictech.com.hk> schreef in bericht >>> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl... >>>> Dim authCommand As String = "select count(*) as >>>> iRowCount from coinfo where loginid = @cocode and ((curr_pwd = @pwd and >>>> effdate > getdate()) or (eff_pwd = @pwd and effdate <= getdate()))" >>>> Dim oleCommand As New OleDbCommand(authCommand, >>>> authConnection) >>>> >>>> oleCommand.Parameters.Add(New OleDbParameter("@cocode", >>>> OleDbType.VarChar, 10)) >>>> oleCommand.Parameters("@cocode").Value = UserName >>>> oleCommand.Parameters.Add(New OleDbParameter("@pwd", >>>> OleDbType.VarChar, 50)) >>>> oleCommand.Parameters("@pwd").Value = UserPassword >>>> >>>> Dim iCount As Integer = >>>> CType(oleCommand.ExecuteScalar(), Integer) <--- error >>>> It said "Missing operand" . Please help >>>> >>>> >>> >>> >> >> > > Cor Ligthert [MVP] wrote:
> Agnes, <snip>> > The OleDBcommand does AFAIK not use named parameters, therefore are it 3 > paremeters, you are offering however only 2. And then Scott M. argued: > Yes Cor, oleDBCommand *can* work with named parameters, but the names must So if I understand you both correctly, the solution to the OP's problem> be in the same order as the parameters are in the parameters collection of > the command itself. would be in the lines of: <code> Dim authCommand As String = "select count(*) as iRowCount " _ & "from coinfo where loginid = @p1 " _ & "and ((curr_pwd = @p2 and effdate > getdate()) " _ & "or (eff_pwd = @p3 and effdate <= getdate()))" Dim oleCommand As New OleDbCommand(authCommand, authConnection) oleCommand.Parameters.Add(New OleDbParameter("@p1", _ OleDbType.VarChar, 10)).Value = UserName oleCommand.Parameters.Add(New OleDbParameter("@p2", _ OleDbType.VarChar, 50)).Value = UserPassword oleCommand.Parameters.Add(New OleDbParameter("@p3", _ OleDbType.VarChar, 50)).Value = UserPassword Dim iCount As Integer = oleCommand.ExecuteScalar() </code> Is this right? Regards, Branco. I don't know. I was just letting Cor know about the use of the
OleDbParameters. I still think that the problem would be more traceable if the code were in a try catch that contained a catch for an OleDbException as well as an Exception. Show quoteHide quote "Branco Medeiros" <branco.medei***@gmail.com> wrote in message news:1156717373.061355.154790@74g2000cwt.googlegroups.com... > Cor Ligthert [MVP] wrote: >> Agnes, >> >> The OleDBcommand does AFAIK not use named parameters, therefore are it 3 >> paremeters, you are offering however only 2. > <snip> > > And then Scott M. argued: >> Yes Cor, oleDBCommand *can* work with named parameters, but the names >> must >> be in the same order as the parameters are in the parameters collection >> of >> the command itself. > > So if I understand you both correctly, the solution to the OP's problem > would be in the lines of: > > <code> > Dim authCommand As String = "select count(*) as iRowCount " _ > & "from coinfo where loginid = @p1 " _ > & "and ((curr_pwd = @p2 and effdate > getdate()) " _ > & "or (eff_pwd = @p3 and effdate <= getdate()))" > > Dim oleCommand As New OleDbCommand(authCommand, authConnection) > > oleCommand.Parameters.Add(New OleDbParameter("@p1", _ > OleDbType.VarChar, 10)).Value = UserName > > oleCommand.Parameters.Add(New OleDbParameter("@p2", _ > OleDbType.VarChar, 50)).Value = UserPassword > > oleCommand.Parameters.Add(New OleDbParameter("@p3", _ > OleDbType.VarChar, 50)).Value = UserPassword > > Dim iCount As Integer = oleCommand.ExecuteScalar() > </code> > > Is this right? > > Regards, > > Branco. > Branco,
I have not really checked it complete, but in principle. Yes. Cor Show quoteHide quote "Branco Medeiros" <branco.medei***@gmail.com> schreef in bericht news:1156717373.061355.154790@74g2000cwt.googlegroups.com... > Cor Ligthert [MVP] wrote: >> Agnes, >> >> The OleDBcommand does AFAIK not use named parameters, therefore are it 3 >> paremeters, you are offering however only 2. > <snip> > > And then Scott M. argued: >> Yes Cor, oleDBCommand *can* work with named parameters, but the names >> must >> be in the same order as the parameters are in the parameters collection >> of >> the command itself. > > So if I understand you both correctly, the solution to the OP's problem > would be in the lines of: > > <code> > Dim authCommand As String = "select count(*) as iRowCount " _ > & "from coinfo where loginid = @p1 " _ > & "and ((curr_pwd = @p2 and effdate > getdate()) " _ > & "or (eff_pwd = @p3 and effdate <= getdate()))" > > Dim oleCommand As New OleDbCommand(authCommand, authConnection) > > oleCommand.Parameters.Add(New OleDbParameter("@p1", _ > OleDbType.VarChar, 10)).Value = UserName > > oleCommand.Parameters.Add(New OleDbParameter("@p2", _ > OleDbType.VarChar, 50)).Value = UserPassword > > oleCommand.Parameters.Add(New OleDbParameter("@p3", _ > OleDbType.VarChar, 50)).Value = UserPassword > > Dim iCount As Integer = oleCommand.ExecuteScalar() > </code> > > Is this right? > > Regards, > > Branco. >
How can I use a dll with several programs?
What exactly does this message mean? vb2005 and ce net 4.2 convert function from VB.6 to VB.NET API found in C# but not VB? DatagridView Column Headers books for vb.net Binding Data to Dataset or Table disable/enable menu items How to find out current Screen resolution? |
|||||||||||||||||||||||