aspx thread: No Errors, but it don't Work.
I wasn't been able to delete a row from an mdb file, so I started with
Edit tasks first...
I been debugging a little time, and now it don't returns errors, but the
aplication don't works aniway.
I imagine that the problem should be in the sql string or in the
definition of my Primary Key (IdF) or maybe in the quotes (but I'm not
sure of that because it compile..)
This is the sourcecode, you can try it with any mdb (adapting it to your
tables..):
---------------------------------------
<%@ Page Language="VB" Debug="True"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
sub Page_Load(obj as Object, e as EventArgs)
'set up connection
dim myConnection as new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath
("borrala.mdb") & ";")
'open connection
dim myCommand as new OleDbDataAdapter ("select * from tbdownloads",
myConnection)
'fill dataset
dim ds as DataSet = new DataSet()
myCommand.Fill(ds, "tbdownloads")
'select data view and bind to server control
DataGrid1.DataSource = ds
DataGrid1.DataMember = "tbdownloads"
DataBind()
end sub
sub DataGrid1_Edit(obj as object, e as DataGridCommandEventArgs)
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
end sub
sub DataGrid1_Update(obj as object, e as DataGridCommandEventArgs)
Dim myConn As OleDbConnection
Dim connStr, sqlStr, strNomFich, strEnlace As String
Dim myUpdateCommand As OleDbCommand
Dim intPid As Integer
intPid=e.Item.ItemIndex
strNomFich=(Ctype(e.Item.Cells(1).Controls(0), Textbox)).Text
strEnlace=(Ctype(e.Item.Cells(2).Controls(0), Textbox)).Text
sqlStr="Update tbdownloads set NomFich=' " + strNomFich + " ',
DescF=' " + StrEnlace + " ' WHERE IdF=" +intPid.ToString
connStr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("borrala.mdb") & ";"
myConn=New OleDbConnection(connStr)
myConn.Open()
myUpdateCommand=New OleDbCommand(sqlStr, myConn)
myUpdateCommand.ExecuteNonQuery
myConn.Close()
DataGrid1.EditItemIndex=-1
DataGrid1.DataBind()
end sub
sub DataGrid1_Cancel(obj as object, e as DataGridCommandEventArgs)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
end sub
sub DataGrid1_SortCommand(obj as Object, _
e as DataGridSortCommandEventArgs)
' sort the data using the SortField property
' of the eventargs
DataGrid1.DataBind()
End Sub
sub DataGrid1_PageIndexChanged(obj as Object, e as
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
end sub
</script>
<html>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server"
BorderColor="black"
GridLines="Vertical"
cellpadding="4"
cellspacing="0"
width="450"
Font-NameFont-Names="Arial"
Font-Size="8pt"
ShowFooter="True"
HeaderStyle-BackColor="#cccc99"
FooterStyle-BackColor="#cccc99"
ItemStyle-BackColor="#ffffff"
AlternatingItemStyle-Backcolor="#cccccc"
AutoGenerateColumns="false"
AllowSorting=true
OnEditCommand="DataGrid1_Edit"
OnCancelCommand="DataGrid1_Cancel"
OnUpdateCommand="DataGrid1_Update"
AllowPaging="True"
PageSize=2
PagerStyle-Mode=NumericPages
PagerStyle-PageButtonCount = 2
OnPageIndexChanged="DataGrid1_PageIndexChanged" >
<Columns>
<asp:TemplateColumn HeaderText="Descripción">
<ItemTemplate>
<asp:Label id="Name" runat="server"
Text='<%# Container.DataItem("Enlace")%>'/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Nombre Fichero"
DataField="NomFich"/>
<asp:BoundColumn HeaderText="Descripción" DataField="DescF"/>
<asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
ItemStyle-Wrap="false"
HeaderText="Edit" />
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
---------------------------------------
Hope anibody have an Idea about what the reasson for it don't update...
Thanks!!
Salvador Gallego.