Hi again,<BR><BR>Thanks, rajasp for your solution but I been not able to put it in practice at all :-(<BR><BR>Aniway I took a Microsoft Quickstar example for deleting and I added it to my code, but when I click on the "Delete" column it returns me the following error:<BR><BR>-------------------------------<BR><BR>Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index <BR>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <BR><BR>Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index<BR><BR>Source Error: <BR><BR><BR>Line 24: objCommand = New OleDbCommand(DeleteCmd, objConnection)<BR>Line 25: objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11))<BR>Line 26: objCommand.Parameters("@Id").Value = http://aspmessageboard.com/archive/index.php/DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex)) --> LINE OF ERROR.<BR>Line 27: <BR>Line 28: objCommand.Connection.Open()<BR><BR>-------------------------------<BR> <BR>I tried a lot of things, but nothing seem to Work.<BR><BR>Here's my code. Any Ideas? (The code uses a form to add a record on a table using a mdb file, then it should delete the selected record, but it don't works..)<BR><BR>Code:<BR><BR>-------------------------------<BR><BR><%@ Page Language="VB" Debug="True"%><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.OleDb" %><BR><BR><script language="VB" runat="server"><BR> ' Declarados Globalmente.<BR> Dim objConnection As OleDbConnection<BR> Dim objCommand As OleDbCommand <BR><BR> Sub Page_Load(Sender As Object, E As EventArgs) <BR> ' Set up our connection.<BR> objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("borrala.mdb") & ";")<BR> If Not (IsPostBack)<BR> ShowDataGrid()<BR> End If<BR> ' Every call to the page adds a new record and<BR> ' shows the data in the table.<BR> End Sub<BR><BR> Sub MyDataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs)<BR><BR> Dim DeleteCmd As String = "DELETE from Employee where IdF = @Id"<BR><BR> objCommand = New OleDbCommand(DeleteCmd, objConnection)<BR> objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11))<BR> objCommand.Parameters("@Id").Value = DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex))<BR><BR> objCommand.Connection.Open()<BR><BR> Try<BR> objCommand.ExecuteNonQuery()<BR> Message.InnerHtml = "<b>Record Deleted</b><BR>" & DeleteCmd<BR> Catch Exc As OleDbException<BR> Message.InnerHtml = "ERROR: Could not delete record"<BR> Message.Style("color") = "red"<BR> End Try<BR><BR> objCommand.Connection.Close()<BR><BR> ShowDataGrid()<BR> End Sub <BR> <BR> Sub AddNewRecord(Sender As Object, E As EventArgs)<BR> Dim strSQLQuery As String<BR> Dim miEnlace As String<BR> Dim Contra As String<BR> <BR> Contra="</a>"<BR> miEnlace="<a href="+""""+Enlace.value+""""+">"+NomFich.value+Contra<BR> <BR> ' Our insert command<BR> strSQLQuery = "INSERT INTO tbdownloads " _<BR> & "(NomFich, Enlace, DescF) " _<BR> & "VALUES (@TextValue, @IntValue, @DTValue)"<BR><BR> ' Create new command object passing it our SQL insert<BR> ' and telling it which connection to use.<BR> objCommand = New OleDbCommand(strSQLQuery, objConnection)<BR> <BR> ' Add parameters that our SQL command takes:<BR> objCommand.Parameters.Add(New OleDbParameter("@TextValue", OleDbType.VarChar, 255))<BR> objCommand.Parameters.Add(New OleDbParameter("@IntValue", OleDbType.VarChar, 255))<BR> objCommand.Parameters.Add(New OleDbParameter("@DTValue", OleDbType.VarChar, 255))<BR><BR> ' Set the values of these parameters:<BR> ' These can obviously come from anywhere... I'm just pulling<BR> ' in strings and numbers from the current time & date so<BR> ' I can keep the sample simple and not involve an input form.<BR> <BR> objCommand.Parameters("@TextValue").Value = NomFich.value<BR> objCommand.Parameters("@IntValue").Value = miEnlace<BR> objCommand.Parameters("@DTValue").Value = DescF.value<BR><BR> ' Open the connection, execute the command, and close the connection.<BR> objConnection.Open()<BR> objCommand.ExecuteNonQuery()<BR> objConnection.Close()<BR> <BR> ' Record is now added... you should add appropriate error<BR> ' checking and handling, but we've left it out simply for<BR> ' clarity and brevity. Either that or I was just too lazy<BR> ' to write it... I don't recall!
<BR> ShowDataGrid<BR> End Sub<BR><BR> Sub ShowDataGrid()<BR> Dim objCommand As OleDbCommand<BR> Dim strSQLQuery As String<BR><BR> ' Get all the records to show<BR> strSQLQuery = "SELECT Enlace, DescF FROM tbdownloads"<BR><BR> ' Create new command object passing it our SQL query<BR> ' and telling it which connection to use.<BR> objCommand = New OleDbCommand(strSQLQuery, objConnection)<BR><BR> ' Open the connection, execute the command, and close the connection.<BR> objConnection.Open()<BR><BR> DBAddDataGrid.DataSource = objCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)<BR> DBAddDataGrid.DataBind()<BR><BR> ' I shouldn't need this, but System.Data.CommandBehavior.CloseConnection<BR> ' is not identical to .Close(). I'm not sure why, but if you move the<BR> ' .Close line above .DataBind, it fails when trying to FieldCount<BR> ' complaining that the reader is closed. On the other hand, if you use<BR> ' CloseConnection it works fine. This makes me think .Close() does more<BR> ' "closing" then CloseConnection so I've included it here just in case.<BR> ' Any ideas on this... send them to [email protected].<BR> objConnection.Close()<BR> End Sub<BR><BR></script><BR><BR><html><BR><body><BR> <form runat="server"><BR><BR> <h3><font face="Verdana"><u>Administrador de Archivos de La Intranet</u></font></h3><BR><center><BR> <table width="95%"><BR> <td valign="top"><BR><BR> <table style="font: 8pt verdana"><BR> <tr><BR> <td colspan="2" bgcolor="#aaaadd" style="font:10pt verdana">A?ade un fichero Nuevo a la Tabla:</td><BR> </tr><BR> <tr><BR> <td nowrap><b>Nombre del Fichero: </b></td><BR> <td><input type="text" id="NomFich" value="Ej: Precios Nokia.pdf" runat="server"></td><BR> </tr><BR> <tr><BR> <td nowrap><b>Enlace: </b></td><BR> <td><input type=file id="Enlace" value="Doe" runat="server"></td><BR> </tr><BR> <tr nowrap><BR> <td><b>Descripci
