Results 1 to 5 of 5

Thread: Index (zero based) must be greater than or equal to zero and less than the size of th

  1. #1

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524

    Unhappy Index (zero based) must be greater than or equal to zero and less than the size of th

    Can you tell me why I am getting the following error from the given code?

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.


    Code is

    Private Sub btnIssue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIssue.Click
    Dim objCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand()
    objCommand.Connection = OleDbConnection1
    objCommand.CommandText = "INSERT INTO TRANS(BOOKNO,MEMBERNO) VALUES (@bookno,@memberno)"
    objCommand.CommandType = CommandType.Text

    objCommand.Parameters.Add("@bookno", editNo)
    objCommand.Parameters.Add("@memberno", editIssue)

    Try
    OleDbConnection1.Open()
    objCommand.ExecuteNonQuery() --> ERROR IN THIS LINE
    OleDbConnection1.Close()
    MessageBox.Show("Book issued", "Issue", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Catch x As System.Exception
    MessageBox.Show(x.ToString, "error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

    End Sub
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  2. #2
    Lively Member
    Join Date
    May 2003
    Posts
    78
    Well this is how I did my Update (and it works) maybe you can compare your insert with my update and spot some difference. I also had problems to do with the ExecuteNonQuery and found the problem was with the sql statement.

    my Update code
    VB Code:
    1. objCommand.Connection = oleDbConnection1
    2.                                     objCommand.CommandText = "UPDATE [" & tablename & "] SET [" & tablename & "].[" & columntoupdate & "] = [" & objDataView.Item(i)(columntoupdate) & "] Where [" & tablename & "].[" & primarykeycol & "] = " & objDataView.Item(i)(primarykeycol)
    3.                                     objCommand.CommandType = CommandType.Text
    4.                                     objCommand.Parameters.Add(New OleDbParameter())
    5.                                     objCommand.Parameters.Item(0).Direction = ParameterDirection.Input
    6.                                     objCommand.Parameters.Item(0).DbType = DbType.Int32
    7.                                     objCommand.Parameters.Item(0).Size = 50
    8.                                     objCommand.Parameters.Item(0).Value = objDataView.Item(i)(cboMarkDup.Text)
    9.                                     objCommand.ExecuteNonQuery()

  3. #3

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524
    Still no luck :-(

    Can you give any code sample, which illustrates entire code right from establishing connection to execute an insert statement?

    Thanx
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  4. #4
    Lively Member
    Join Date
    May 2003
    Posts
    78
    Well I guess your connection is OK if you can get the table in the first place (you can right?)

    IF not you could try comparing it to my long winded connection string which is:

    VB Code:
    1. OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" & PUTYOURDBLOCATIONPATHHERE & ";Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System da" & _
    2.         "tabase="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:En" & _
    3.         "gine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=" & _
    4.         "2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OL" & _
    5.         "EDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don'" & _
    6.         "t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Je" & _
    7.         "t OLEDB:SFP=False"

    Have you tried creating your insert SQL statement in access getting it to work there and then just copying the SQL to your vb code?

    I dont have an INSERT set of code only an UPDATE one which I have given you.

    Try the SQL access thing, it might show some differences.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    From the error you stated

    One of these parameters is either null or missing.... you should write the entire set of values to be inserted to the console window if possible before executing the SQL statement.


    "INSERT INTO TRANS(BOOKNO,MEMBERNO) VALUES (@bookno,@memberno)"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width