Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Parameters.count equals 0

tradmtradm Posts: 49Member
I am using VB.NET 2005 to access a MySQL 5 database.
I expected the following code snippet to give me a parameter count of 3 but it gives me 0.
Note:

- The connection to DB is established (tested)

Any ideas?
Please help!

[code]'Create a connection to DB
Dim cn as New ADODB.Connection
cn.Mode = ADODB.ConnectModeEnum.adModeReadWrite
cn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
cn.Open("MyDSN_Name_ODBC")

'Run Parameter Query
Dim cmd As New ADODB.Command
cmd.ActiveConnection = cn
cmd.CommandText = "INSERT INTO `tblgroups` ( " & _
" `groupID` , `GroupName` , `Description` " & _
" ) VALUES ( " & _
" ? , ? , ? " & _
")"
'Debug
Msgbox(cmd.Parameters.count) ' It gives me 0, WHY????
...[/code]

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    I have never used this style of code... Is it possible that it says that the count is 0 because you didn't add any parameters? You added Command text, but I think that is different from the Parameters object.

    I will have to double check when I am home from vacation, I do not have my computer here, posting from my family's computer.

    Hope you enjoyed your turkey day...
    Sean C
  • tradmtradm Posts: 49Member
    : I have never used this style of code... Is it possible that it says
    : that the count is 0 because you didn't add any parameters? You added
    : Command text, but I think that is different from the Parameters
    : object.
    :
    : I will have to double check when I am home from vacation, I do not
    : have my computer here, posting from my family's computer.
    :
    : Hope you enjoyed your turkey day...
    : Sean C

    Sean,

    I have explicitly added ther parameters and the code is now working ;)

    With Ms SQL 2000, the parameters are automatically "created" (for some reasons the command object is intelligent enough to define the params based on the count of '?' and the data types from the table being referenced in the query)

    Thanks
    Mike.
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Glad you got things working,
    Happy Coding,
    firesickle.com
Sign In or Register to comment.