<br><font size=2 face="sans-serif">Dobry den,</font>
<br>
<br><font size=2 face="sans-serif">Asi IronPython+ADO.NET zatial este moc
ludi nepouziva, ked mi nikto neodpovedal na moju predoslu otazku :-)</font>
<br><font size=2 face="sans-serif">Medzitym sa mi podarilo zistit ako sa
pouziva DataSet+DataAdapter a tu pripajam funkcny priklad.</font>
<br>
<br><font size=2 face="sans-serif">Poznamka: </font>
<br><font size=2 face="sans-serif">DataSet v ADO.NET sa podoba na Recordset
v ADO, s tym hlavnym rozdielom ze moze obsahovat viac tabuliek.</font>
<br>
<br><font size=2 face="Courier New">----- priklad -----</font><font size=3>
</font><font size=2 face="Courier New"><br>
...</font><font size=3> </font>
<br><font size=2 face="Courier New">### Pouzitie ADO.NET</font>
<br><font size=2 face="Courier New">import clr</font>
<br><font size=2 face="Courier New">import System</font>
<br><font size=2 face="Courier New">clr.AddReference("System.Data")</font>
<br><font size=2 face="Courier New">import System.Data</font>
<br>
<br><font size=2 face="Courier New">from System.Data.OleDb import OleDbConnection
as dbconnection</font>
<br><font size=2 face="Courier New">from System.Data.OleDb import OleDbDataAdapter
as dbdataadapter</font>
<br><font size=2 face="Courier New">from System.Data import DataSet as
dataset</font>
<br>
<br><font size=2 face="Courier New"># Connection String</font>
<br><font size=2 face="Courier New">connectstr='PROVIDER=IBMDA400.DataSource.1;DATA
SOURCE='+csebk+'; USER ID='+userid+'; PASSWORD='+pwd</font>
<br><font size=2 face="Courier New">#print connectstr</font>
<br>
<br><font size=2 face="Courier New"># Vytvorit spojenie</font>
<br><font size=2 face="Courier New">dbconn=dbconnection(connectstr)</font>
<br><font size=2 face="Courier New">dbconn.Open()</font>
<br>
<br><font size=2 face="Courier New"># Vytvorit SQL Statement</font>
<br><font size=2 face="Courier New">sqlStatement = "SELECT * FROM
r000100T.r000270V"</font>
<br><font size=2 face="Courier New">#sqlStatement = "SELECT * FROM
r000100T.p400100v"</font>
<br><font size=2 face="Courier New"># DataAdapter</font>
<br><font size=2 face="Courier New">da = dbdataadapter(sqlStatement, dbconn)</font>
<br>
<br><font size=2 face="Courier New"># Vytvorit DataSet</font>
<br><font size=2 face="Courier New">#ds = System.Data.DataSet("MyDataSet")</font>
<br><font size=2 face="Courier New">ds=dataset("MyDataSet")</font>
<br>
<br><font size=2 face="Courier New"># Naplnit Dataset</font>
<br><font size=2 face="Courier New">da.Fill(ds, "MyTable")</font>
<br>
<br><font size=2 face="Courier New"># Vylistovat tabulky v DataSete</font>
<br><font size=2 face="Courier New">for table in ds.Tables:</font>
<br><font size=2 face="Courier New"> print table</font>
<br>
<br><font size=2 face="Courier New"># Vylistovat vybrane polia vo vsetkych
riadkoch 1.tabulky DataSetu</font>
<br><font size=2 face="Courier New">count=0</font>
<br><font size=2 face="Courier New">for row in ds.Tables[0].Rows:</font>
<br><font size=2 face="Courier New"> count +=1</font>
<br><font size=2 face="Courier New"> print "%10s %10s %10s %10s"
% (row[0], row[1], row[2], row[3])</font>
<br>
<br><font size=2 face="Courier New">print "pocet viet v tabulke je:
%d" % count</font>
<br>
<br><font size=2 face="Courier New"># Ukoncit spojenie</font>
<br><font size=2 face="Courier New">dbconn.Close()</font>
<br><font size=2 face="Courier New">----- koniec prikladu -----</font><font size=3>
</font>
<br>
<br><font size=1 color=#800080 face="sans-serif">----- Forwarded by Roman
Miklos/RZB/PSS on 27.09.2006 18:01 -----</font>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Roman Miklos <RMiklos@pss.sk></b>
</font>
<br><font size=1 face="sans-serif">Sent by: python-bounces@py.cz</font>
<p><font size=1 face="sans-serif">19.09.2006 17:37</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
Konference PyCZ <python@py.cz></font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">"Konference PyCZ"
<python@py.cz></font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">[python] Fw: IronPython
& ADO.NET</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
Dobry den, <br>
<br>
Skusal ste niekto pristup do databazy cez ADO.NET a IronPython? <br>
<br>
Napr. toto citanie pomocou Readeru mi funguje:</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
----- priklad -----</font><font size=3> </font><font size=2 face="Courier New"><br>
...</font><font size=3> </font><font size=2 face="Courier New"><br>
### Pouzitie ADO.NET</font><font size=3> </font><font size=2 face="Courier New"><br>
import clr</font><font size=3> </font><font size=2 face="Courier New"><br>
import System</font><font size=3> </font><font size=2 face="Courier New"><br>
clr.AddReference("System.Data")</font><font size=3> </font><font size=2 face="Courier New"><br>
import System.Data</font><font size=3> </font><font size=2 face="Courier New"><br>
from System.Data.OleDb import OleDbConnection as dbconnection</font><font size=3>
</font><font size=2 face="Courier New"><br>
<br>
# Connection String</font><font size=3> </font><font size=2 face="Courier New"><br>
connectstr='PROVIDER=IBMDA400.DataSource.1;DATA SOURCE='+csebk+'; USER
ID='+userid+'; PASSWORD='+pwd</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
# Vytvorit spojenie</font><font size=3> </font><font size=2 face="Courier New"><br>
dbcon=dbconnection(connectstr)</font><font size=3> </font><font size=2 face="Courier New"><br>
dbcon.Open()</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
# Vytvorit SQL Command</font><font size=3> </font><font size=2 face="Courier New"><br>
dbcmd = dbcon.CreateCommand()</font><font size=3> </font><font size=2 face="Courier New"><br>
dbcmd.CommandText = "SELECT * FROM r000100T.r000270V"</font><font size=3>
</font><font size=2 face="Courier New"><br>
<br>
# Citat data</font><font size=3> </font><font size=2 face="Courier New"><br>
reader = dbcmd.ExecuteReader()</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
count=0</font><font size=3> </font><font size=2 face="Courier New"><br>
while reader.Read():</font><font size=3> </font><font size=2 face="Courier New"><br>
count +=1 </font><font size=3> </font><font size=2 face="Courier New"><br>
print "%10s %10s %10s %10s" % (reader[0], reader[1], reader[2],
reader[3]) </font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
print "pocet viet v tabulke je: %d" % count</font><font size=3>
</font><font size=2 face="Courier New"><br>
<br>
# zavret reader</font><font size=3> </font><font size=2 face="Courier New"><br>
reader.Close()</font><font size=3> </font><font size=2 face="Courier New"><br>
</font><font size=3> </font><font size=2 face="Courier New"><br>
# Ukoncit spojenie</font><font size=3> </font><font size=2 face="Courier New"><br>
dbcon.Close()</font><font size=3> </font><font size=2 face="Courier New"><br>
----- koniec prikladu -----</font><font size=3> <br>
<br>
</font><font size=2 face="sans-serif"><br>
<br>
Ked ale skusim pouzit dataadapter a dataset, t.j. zhruba takto </font><font size=2 face="Courier New"><br>
<br>
----- priklad -----</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
...</font><font size=3> </font><font size=2 face="Courier New"><br>
from System.Data.OleDb import OleDbConnection as dbconnection</font><font size=3>
</font><font size=2 face="Courier New"><br>
from System.Data.OleDb import OleDbDataAdapter as dbdataadapter</font><font size=3>
</font><font size=2 face="Courier New"><br>
from System.Data import DataSet as dataset</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
# Connection String</font><font size=3> </font><font size=2 face="Courier New"><br>
DSN='PROVIDER=IBMDA400.DataSource.1;DATA SOURCE='+csebk+'; USER ID='+userid+';
PASSWORD='+pwd</font><font size=3> </font><font size=2 face="Courier New"><br>
print DSN</font><font size=3> </font><font size=2 face="Courier New"><br>
conn=dbconnection(DSN)</font><font size=3> </font><font size=2 face="Courier New"><br>
conn.Open()</font><font size=3> </font><font size=2 face="Courier New"><br>
<br>
dataadapter = dbdataadapter("SELECT * FROM r000100T.r000270V",
conn)</font><font size=3> </font><font size=2 face="Courier New"><br>
#rs = System.Data.DataSet("MyDataSet")</font><font size=3> </font><font size=2 face="Courier New"><br>
rs=dataset("MyDataSet")</font><font size=3> </font><font size=2 face="Courier New"><br>
dataadapter.Fill(rs,"MyTable")</font><font size=3> </font><font size=2 face="Courier New"><br>
#print rs</font><font size=3> </font><font size=2 face="Courier New"><br>
row= rs.Tables(0).Rows(0)</font><font size=3> </font><font size=2 face="Courier New"><br>
...</font><font size=3> </font><font size=2 face="Courier New"><br>
----- koniec prikladu -----</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
dostanem na poslednom uvedenom riadku chybu <br>
"DataTableCollection object is not callable"</font><font size=3>
</font><font size=2 face="sans-serif"><br>
<br>
Mate niekto funkcny priklad jak pouzit DataSet v IronPythone?</font><font size=3>
</font><font size=2 face="sans-serif"><br>
<br>
Mgr. Ing. Roman MIKLÓ© <br>
Prvá stavebná sporiteµňa a.s. <br>
Bajkalská 30, P. O. Box 48 <br>
829 48 Bratislava 25 <br>
Tel.: +421/ 2 / 582 31 174 <br>
Fax: +421/ 2 / 582 31 109</font><font size=3> </font><font size=2><tt><br>
<br>
Mgr. Ing. Roman MIKLÓ© <br>
Prvá stavebná sporiteµňa a.s. <br>
Bajkalská 30, P. O. Box 48 <br>
829 48 Bratislava 25 <br>
Tel.: +421/ 2 / 582 31 174 <br>
Fax: +421/ 2 / 582 31 109 _______________________________________________<br>
Python mailing list<br>
Python@py.cz<br>
http://www.py.cz/mailman/listinfo/python</tt></font><font size=2 face="sans-serif"><br>
Mgr. Ing. Roman MIKLÓ© <br>
Prvá stavebná sporiteµňa a.s. <br>
Bajkalská 30, P. O. Box 48 <br>
829 48 Bratislava 25 <br>
Tel.: +421/ 2 / 582 31 174 <br>
Fax: +421/ 2 / 582 31 109 <br>
</font>