Asked by:
Fckeditor data saving issues

Question
-
User-1067288919 posted
Hello folks, i am sorry if this is in the wrong section. Please put this in the right one.
I have never used fckeditor and i was hoping to get HTML formatted text into my MS Access database hence i went with this module. I added fck editor and everything seems to we working, but when i add the code to add values in my database it throws up an error. Please have a look and tell me where i have gone wrong and correct me please.
Thanks and Regards in advance
This is the full page code
<%@ Page Language="VB" MasterPageFile="~/Admin.master" Title="Untitled Page" %> <%@ Import Namespace="System.Web.Mail" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Configuration" %> <%@ Import Namespace="System.Collections" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %> <%@ Import Namespace="System.Web.UI.HtmlControls" %> <%@ Register assembly="FredCK.FCKeditorV2" namespace="FredCK.FCKeditorV2" tagprefix="FCKeditorV2" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then Dim connection As OleDbConnection = CreateConnection() Dim command As New OleDbCommand("SELECT lbody FROM links WHERE lid = ?", connection) command.Parameters.Add("lid", Request.QueryString.[Get](0)) Dim record As OleDbDataReader = command.ExecuteReader() If record.Read() Then tbbody.Value = record.GetString(0) Else tbbody.Value = "" End If record.Close() connection.Close() End If End Sub Private Function CreateConnection() As OleDbConnection Dim connection As New OleDbConnection() 'Creating new OleDbConnection 'Creating the ConnectionString - Note that it points to the this.TemplateSourceDirectory + "\\News.mdb"; (~/News.mdb) connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.MapPath(Me.TemplateSourceDirectory + "\App_Data\newsdb.mdb") + ";User ID=;Password=;" connection.Open() Return connection End Function Protected Sub btnews_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|newsdb.mdb" Dim SqlString As String = "Update links Set lbody = ? WHERE lid= ?" Using conn As New OleDbConnection(ConnString) Using cmd As New OleDbCommand(SqlString, conn) cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue("lbody", tbbody.Value) cmd.Parameters.AddWithValue("lid", Request.QueryString("lid")) conn.Open() cmd.ExecuteNonQuery() End Using End Using 'RegisterStartupScript("load", "<script type=""text/javascript"">" & Chr(10) & "" + "self.close();" & Chr(10) & "" + "<" + "/script>") Response.Redirect("admin_news.aspx") End Sub </script> <asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1"> <span class="bodyTitle">Edit News</span> <br /> <br /> <br /> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="style2" > </td> <td> </td> </tr> <tr> <td class="style5" valign="top">New Link :</td> <td width="70%"> <FCKeditorV2:FCKeditor ID="tbbody" runat="server"> </FCKeditorV2:FCKeditor> </td> </tr> <tr> <td class="style2"> </td> <td> </td> </tr> <tr> <td class="style2"> </td> <td> <asp:Button ID="btcancel" runat="server" CssClass="button_small" ForeColor="Black" Text="Cancel" /> <asp:Button ID="btnews" runat="server" CssClass="button_small" ForeColor="Black" Text="Update" onclick="btnews_Click" /></td> <asp:AccessDataSource ID="adsnews" runat="server" DataFile="~/App_Data/newsdb.mdb" SelectCommand="SELECT * FROM wishlist WHERE (wid = ?)"> </asp:AccessDataSource> </tr> </table> </asp:Content>
And this is the error that it throws up.
Server Error in '/' Application. -------------------------------------------------------------------------------- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index 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. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source Error: Line 26: Dim command As New OleDbCommand("SELECT lbody FROM links WHERE lid = ?", connection) Line 27: Line 28: command.Parameters.Add("lid", Request.QueryString.[Get](0)) Line 29: Dim record As OleDbDataReader = command.ExecuteReader() Line 30: If record.Read() Then Source File: C:\Documents and Settings\Gajanan\Desktop\akani.org.za\admin_linktest.aspx Line: 28 Stack Trace: [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index] System.Collections.ArrayList.get_Item(Int32 index) +7485640 System.Collections.Specialized.NameObjectCollectionBase.BaseGet(Int32 index) +13 System.Collections.Specialized.NameValueCollection.Get(Int32 index) +8 ASP.admin_linktest_aspx.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Gajanan\Desktop\akani.org.za\admin_linktest.aspx:28 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43 System.Web.UI.Control.OnLoad(EventArgs e) +73 System.Web.UI.Control.LoadRecursive() +52 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2184 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
Thanks.
Tuesday, May 26, 2009 7:27 AM
All replies
-
User-1853252149 posted
Start here:
Jeff
Tuesday, May 26, 2009 8:26 AM -
User-1067288919 posted
Hi jeff
I changed command.Parameters.Add("lid", Request.QueryString.[Get](0)) to
command.Parameters.AddWithValue("lid", Request.QueryString.[Get](0))
still it makes no difference. Am i making some mistake in the syntax ? I checked the link but most of the problems people are having are not similar to mine. Can you please explain what this error means and how to correct it ?
Thanks and Regards.
Tuesday, May 26, 2009 8:43 AM