|
-
Aug 10th, 2003, 12:42 PM
#1
Thread Starter
Fanatic Member
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.
-
Aug 11th, 2003, 10:13 AM
#2
Lively Member
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:
objCommand.Connection = oleDbConnection1
objCommand.CommandText = "UPDATE [" & tablename & "] SET [" & tablename & "].[" & columntoupdate & "] = [" & objDataView.Item(i)(columntoupdate) & "] Where [" & tablename & "].[" & primarykeycol & "] = " & objDataView.Item(i)(primarykeycol)
objCommand.CommandType = CommandType.Text
objCommand.Parameters.Add(New OleDbParameter())
objCommand.Parameters.Item(0).Direction = ParameterDirection.Input
objCommand.Parameters.Item(0).DbType = DbType.Int32
objCommand.Parameters.Item(0).Size = 50
objCommand.Parameters.Item(0).Value = objDataView.Item(i)(cboMarkDup.Text)
objCommand.ExecuteNonQuery()
-
Aug 13th, 2003, 04:17 AM
#3
Thread Starter
Fanatic Member
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.
-
Aug 14th, 2003, 05:07 AM
#4
Lively Member
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:
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" & _
"tabase="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:En" & _
"gine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=" & _
"2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OL" & _
"EDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don'" & _
"t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Je" & _
"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.
-
Aug 16th, 2003, 10:31 AM
#5
I wonder how many charact
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|