python操作access
1. python如何連接有密碼的Access資料庫並且查詢數據
importpyodbc
dbfile="db2.mdb"
try:
conn=pyodbc.connect('DRIVER={MicrosoftAccessDriver(*.mdb)};PWD=thepwd;DBQ='+dbfile)
cur=conn.cursor()
cur.execute("select*fromstandard")
printcur.fetchone()
printdir(cur)
exceptpyodbc.Error,e:
printe[1]
exceptpyodbc.ProgrammingError,e:
printe[1]
2. python 操作ACCESS資料庫中 如何刪除記錄
3、增加欄位:
CString
msql
=
"ALTER
TABLE
student
ADD
COLUMN
zian
char(30)";
mdatabase。ExecuteSQL(msql);。。添加名為3zizhuan的欄位到名為5student的表中6。
4、新紀版錄:
msqlstr
=
"INSERT
INTO
student
(學號,姓名,數學)
VALUES
('5014','jack','67')";
mdatabase。ExecuteSQL(msql);。。添加學號為權55071,姓名為4jack,數學為062的一i行記錄
到表student中0。
0、刪除:
CString
msql
=
「DELETE
FROM
student
WHERE
學號
=
'1012'」;
mdatabase。ExecuteSQL(msql);。。刪除學號為48006的一d行記錄。
w鼎ヲ∞ai蓿n′一h≈jn′一ul
3. python 怎麼操作access資料庫
#!/usr/bin/envpython
#-*-conding:utf-8-*-
importpypyodbc
if__name__=="__main__":
str='Driver={MicrosoftAccessDriver(*.mdb)};DBQ=E:\123.mdb'
conn=pypyodbc.win_connect_mdb(str)
#conn=pypyodbc.connect(str)
cur=conn.cursor()
cur.execute("SELECT*FROMcatalog")
forrowincur.fetchall():
forfieldinrow:
printfield,
print''
conn.commit()
cur.close()
conn.close()
4. python讀取數據access出錯
DSN
=
'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=D:\Data.mdb;'
把D:\Data.mdb改成d:\\Data.mdb就行了。
python裡面\是個特殊的釋放符號。
推薦在字元串版前面加上權r標志。標識字元串是原生態,裡面的釋放符號都是原始符號
;)
推薦這樣寫:
DSN
=
r'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=D:\Data.mdb;'
5. python連接access資料庫問題
資料庫能打開是什麼意思。。。用什麼打開的
你的ODBC設置好了嗎。。。
6. 如何在Python 中導入access 數據
Python操作Access資料庫步驟之1、建立資料庫連接
import win32com.client
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/MyDB.mdb;'
conn.Open(DSN)
Python操作Access資料庫步驟之2、打開一個記錄集
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs_name = 'MyRecordset'#表名
rs.Open('[' + rs_name + ']', conn, 1, 3)
Python操作Access資料庫步驟之3、對記錄集操作
rs.AddNew()
rs.Fields.Item(1).Value = 'data'
rs.Update()
Python操作Access資料庫步驟之4、用SQL來插入或更新數據
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/MyDB.mdb;'
sql_statement = "Insert INTO [Table_Name] ([Field_1],
[Field_2]) VALUES ('data1', 'data2')"
conn.Open(DSN)
conn.Execute(sql_statement)
conn.Close()
Python操作Access資料庫步驟之5、遍歷記錄
rs.MoveFirst()
count = 0
while 1:
if rs.EOF:
break
else:
countcount = count + 1
rs.MoveNext()
注意:如果一個記錄是空的,那麼將指針移動到第一個記錄將導致一個錯誤,因為此時recordcount是無效的。解決的方法是:打開一個記錄集之前,先將Cursorlocation設置為3,然後再打開記錄集,此時recordcount將是有效的。例如:
rs.Cursorlocation = 3 # don't use parenthesis here
rs.Open('Select * FROM [Table_Name]', conn) # be sure conn is open
rs.RecordCount # no parenthesis here either
7. Python_access
access( path, mode)
Use the real uid/gid to test for access to path. Note that most operations will use the effective uid/gid, therefore this routine can be used in a suid/sgid environment to test if the invoking user has the specified access to path. mode should be F_OK to test the existence of path, or it can be the inclusive OR of one or more of R_OK, W_OK, and X_OK to test permissions. Return True if access is allowed, False if not. See the Unix man page access(2) for more information. Availability: Macintosh, Unix, Windows.
Note: Using access() to check if a user is authorized to e.g. open a file before actually doing so using open() creates a security hole, because the user might exploit the short time interval between checking and opening the file to manipulate it.
Note: I/O operations may fail even when access() indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model.
可以看看幫助
8. 如何在Python 中導入access 數據
Python操作Access資料庫步驟之1、建立資料庫連接
import win32com.client
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/MyDB.mdb;'
conn.Open(DSN)
Python操作Access資料庫步驟之2、打開一個記錄集
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs_name = 'MyRecordset'#表名
rs.Open('[' + rs_name + ']', conn, 1, 3)
Python操作Access資料庫步驟之3、對記錄集操作
rs.AddNew()
rs.Fields.Item(1).Value = 'data'
9. python怎麼開發access操作
在EXCEL中執行的代碼是VBA,也就也是VB的一個子集,宏也就也一段VB代碼,python腳本好象不能在其中運行,但如果是可執行的程序可以利用VB代碼調用