Allora sotto riporto il codice che ho utilizzato per imparare ad utilizzare ADO.NET.
Creo una connessione riempio un dataset e poi cerco di modificarlo (stampando le modifiche)
fino alla seconda stampata tutto ok alla terza stampata però mi viene fuori un errore con un'indice dell'array oltrepassato ma non ho capito per quale motivo
lo testate?
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load (obj as Object, e as EventArgs)
dim Con as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\esempi\prova.mdb")
Dim ds AS new DataSet("MyDataSet")
Dim objCmd as new OleDbDataAdapter ("SELECT * FROM tblUsers WHERE id < 10", Con)
objCmd.Fill(ds,"tblUsers")
'Prima Stampata
Dim dTable as DataTable = ds.Tables("tblUsers")
Dim CurrRows() as DataRow = dTable.Select(Nothing, Nothing, DataViewRowState.CurrentRows)
Dim I, J as integer
Dim strOutput as String
FOR I = 0 to CurrRows.Length - 1
FOR J = 0 TO dTable.Columns.Count - 1
strOutput = strOutput & dTable.Columns(J).ColumnName & " = " & CurrRows(I)(J).ToString & " "
NEXT
strOutput = strOutput & "<hr>"
NEXT
Response.Write(strOutput)
Response.Write("
")
ds.Tables("tblUsers").Rows(2)(3) = "Faccia di Merda"
'Seconda Stampata
Dim dTable2 as DataTable = ds.Tables("tblUsers")
Dim CurrRows2() as DataRow = dTable2.Select(Nothing, Nothing, DataViewRowState.CurrentRows)
Dim I2, J2 as integer
Dim strOutput2 as String
FOR I2 = 0 to CurrRows2.Length - 1
FOR J2 = 0 TO dTable2.Columns.Count - 1
strOutput2 = strOutput2 & dTable2.Columns(J2).ColumnName & " = " & CurrRows(I2)(J2).ToString & " "
NEXT
strOutput2 = strOutput2 & "<hr>"
NEXT
Response.Write(strOutput2)
dim dr as DataRow = ds.Tables("tblUsers").NewRow()
dr(0) = "100"
dr(1) = "Zampetti"
dr(2) = "Via della Cacca 2902"
dr(3) = "Sant'Odorico"
dr(4) = "UD"
dr(5) = "1981"
dr(6) = "320392938329393"
dr(7) = "339-5031146"
ds.Tables("tblUsers").Rows.Add(dr)
'Terza Stampata
Dim dTable3 as DataTable = ds.Tables("tblUsers")
Dim CurrRows3() as DataRow = dTable3.Select(Nothing, Nothing, DataViewRowState.CurrentRows)
Dim I3, J3 as integer
Dim strOutput3 as String
FOR I3 = 0 to CurrRows3.Length - 1
FOR J3 = 0 TO dTable3.Columns.Count - 1
strOutput3 = strOutput3 & dTable3.Columns(J3).ColumnName & " = " & CurrRows(I3)(J3).ToString & " "
NEXT
strOutput3 = strOutput3 & "<hr>"
NEXT
Response.Write(strOutput3)
objCmd.UpdateCommand = new OleDbCommand
objCmd.UpdateCommand.cOmmandText = "Update tblUsers SET city='ASPVille' WHERE id = 3"
objCmd.UpdateCommand.Connection = Con
objCmd.InsertCommand = new OleDbCommand
objCmd.InsertCommand.CommandText = "INSERT INTO tblUsers(nome, cognome,indirizzo) VALUES ('Lurido', 'Lurido', 'Stronzo')"
objCmd.InsertCommand.Connection = Con
end sub
function Stampa(dtSt as DataSet)
end function
</script>