Jump to content
Sign in to follow this  
Chinasmoker

AddNew error

Recommended Posts

Chinasmoker

Access database

My script can insert a data,but use AddNew error,

CODE
$dbname = (@DesktopDir & "\db1.mdb")

$tblname = "T1"

$fldname = "F1"

$T = "*"

$addfld = ObjCreate("ADODB.Connection")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)

$addfld.Execute("Insert Into "& $tblname &"(F1)" &"values('www')")

$RS =ObjCreate("ADODB.Recordset")

$RS.ActiveConnection = $addfld

$RS.Open ("Select "&$T & " From " & $tblname )

$RS.AddNew

$RS.Fields(1) = "12345"

msgbox(0,"",$RS.Fields(0).Name)

msgbox(0,"",$RS.Fields(0).Value)

$RS.Update

$addfld.Close


One is never too old to learn

Share this post


Link to post
Share on other sites
LOULOU

Access database

My script can insert a data,but use AddNew error,

CODE
$dbname = (@DesktopDir & "\db1.mdb")

$tblname = "T1"

$fldname = "F1"

$T = "*"

$addfld = ObjCreate("ADODB.Connection")

$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)

$addfld.Execute("Insert Into "& $tblname &"(F1)" &"values('www')")

$RS =ObjCreate("ADODB.Recordset")

$RS.ActiveConnection = $addfld

$RS.Open ("Select "&$T & " From " & $tblname )

$RS.AddNew

$RS.Fields(1) = "12345"

msgbox(0,"",$RS.Fields(0).Name)

msgbox(0,"",$RS.Fields(0).Value)

$RS.Update

$addfld.Close

Another approach

CODE
$objconn1 = ObjCreate("ADODB.Connection")

$objrs1 = ObjCreate("ADODB.Recordset")

$objconn1.Open = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & $dbname & ";"

$requete = "Insert Into "& $tblname &"(F1)" &"values('www');"

$objrs1.Open ($requete, $objconn1, $adOpenStatic, $adLockOptimistic)

$requete = "Select * From " & $tblname& ";"

$objrs1.Open ($requete, $objconn1, $adOpenStatic, $adLockOptimistic)

$OBJRS1.AddNew

$objrs1.Fields("F1") = "12345"

$objrs1.Update

msgbox(0,"",$RS.Fields(0).Name)

msgbox(0,"",$RS.Fields(0).Value)

$objrs1=0

$objconn1.close

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×