pythonでアクセスクエリの結果を配列に入れる
1061 ワード
ソリューション:コードは次のとおりです.
import numpy
import win32com.client # win32
conn = win32com.client.Dispatch(r"ADODB.Connection") # win32 ADODB
DSN = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ex15ConnectAccess_DataIn.accdb;Persist Security Info=False;' # data Source
conn.Open(DSN) #
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs_name = 'ComsumeDetail_Table' #
rs.Open('select * FROM ' + rs_name + ' where id < 500', conn, 1, 3) # SQL
list = [] #
list1=[] # ,
count=0 #
rs.MoveFirst()#
while True:
if rs.EOF: #EOF ( , )
break
else:
for i in range(rs.Fields.Count): # rs.Fields.Count
list.append(rs.Fields[i].Value) #
rs.MoveNext() #
list1.append(list) #
count=count+1
list = [] #
list1=numpy.array(list1) # numpy ,
print(list1)
print(count)