ADO Recordset Opens as Read Only

W

Wayne Wengert

I am trying to rewrite a VB6 App in VB.NET but, from what I understand, I
must use ADO/ADOX to create a database. I tried to copy over my o;ld VB6
code that creates the DB, Creates a table and then adds the 1st record (a
contol record). The code that attempts to set the values for that 1st record
has errors claiming it is Read Only? (see relevant code below)

Questions:

1. Why is that recordset ReadOnly?

2. Can I create the table in VB.NET - if so - How?


================== code ====================
myRS = New ADODB.Recordset()

myRS.CursorType = adOpenKeyset

myRS.Open("[" & TableName & "]", myConn, adOpenDynamic, adLockOptimistic)

'*** Create control record ***

With myRS

..AddNew()

..Fields("Unit") = "$$$$"
 
P

Paul Clement

¤ I am trying to rewrite a VB6 App in VB.NET but, from what I understand, I
¤ must use ADO/ADOX to create a database. I tried to copy over my o;ld VB6
¤ code that creates the DB, Creates a table and then adds the 1st record (a
¤ contol record). The code that attempts to set the values for that 1st record
¤ has errors claiming it is Read Only? (see relevant code below)
¤
¤ Questions:
¤
¤ 1. Why is that recordset ReadOnly?
¤
¤ 2. Can I create the table in VB.NET - if so - How?
¤
¤
¤ ================== code ====================
¤ myRS = New ADODB.Recordset()
¤
¤ myRS.CursorType = adOpenKeyset
¤
¤ myRS.Open("[" & TableName & "]", myConn, adOpenDynamic, adLockOptimistic)
¤
¤ '*** Create control record ***
¤
¤ With myRS
¤
¤ .AddNew()
¤
¤ .Fields("Unit") = "$$$$"

I don't see where you establish your database connection. Is there some code missing here?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
W

Wayne Wengert

Sorry - the connection "myConn" is established in the code that created the
database - that seems to work fine.

Wayne

Paul Clement said:
¤ I am trying to rewrite a VB6 App in VB.NET but, from what I understand, I
¤ must use ADO/ADOX to create a database. I tried to copy over my o;ld VB6
¤ code that creates the DB, Creates a table and then adds the 1st record (a
¤ contol record). The code that attempts to set the values for that 1st record
¤ has errors claiming it is Read Only? (see relevant code below)
¤
¤ Questions:
¤
¤ 1. Why is that recordset ReadOnly?
¤
¤ 2. Can I create the table in VB.NET - if so - How?
¤
¤
¤ ================== code ====================
¤ myRS = New ADODB.Recordset()
¤
¤ myRS.CursorType = adOpenKeyset
¤
¤ myRS.Open("[" & TableName & "]", myConn, adOpenDynamic, adLockOptimistic)
¤
¤ '*** Create control record ***
¤
¤ With myRS
¤
¤ .AddNew()
¤
¤ .Fields("Unit") = "$$$$"

I don't see where you establish your database connection. Is there some code missing here?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top