Click here to Skip to main content
15,883,809 members
Articles / Programming Languages / SQL
Tip/Trick

Store Large Amounts of Data using FCKeditor

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
14 Sep 2012CPOL 12.3K   262   6   1
How to insert and load large amounts of data with formatting using FCKeditor
Sample Image

Introduction

In basic ASP.NET, FCKeditor can be easily used to insert large amounts of data.

Step 1 - Download

Download the FCKeditor from here.

Step 2 - Create Table

SQL
CREATE TABLE [dbo].[Document]
 (
 [Doc ID] [int] NOT NULL,
 [Document] [image] NULL
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
    (
        [Doc ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, 
           ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
 ) 
 ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Step 3 - Initialize FCKeditor

JavaScript
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" 
TagPrefix="FCKeditorV2" %>

Using the Code

Insert Information from FCKeditor

C#
 private void SaveData()
    {
        try
        {
            dc.CreateConnection();
            dc.Open();

            long id = dc.GetNextID("[Document]", "[Doc ID]");

            string strSQL = @"INSERT INTO  
                                [dbo].[Document]
                               (
                                [Doc ID]
                               ,[Document]
                                )
                                VALUES
                               (
                                @id,
                                @Doc
                                )";

            SqlConnection con = dc.GetConnection();
            SqlCommand cmd = new SqlCommand(strSQL, con);

            Byte[] rtf = new Byte[FCK.Value.Length];
            rtf = Encoding.ASCII.GetBytes(FCK.Value);

            SqlParameter fileContent = new SqlParameter();
            fileContent.ParameterName = "@Doc";

            fileContent.SqlDbType = SqlDbType.Image;
            fileContent.Size = rtf.Length;
            fileContent.Value = rtf;

            SqlParameter vid = new SqlParameter();
            vid.ParameterName = "@id";

            vid.SqlDbType = SqlDbType.BigInt;
            vid.Value = id;

            cmd.Parameters.Add(fileContent);
            cmd.Parameters.Add(vid);


            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            dc.Close();
        }
    }
}

Load Information from FCKeditor

C#
private void LoadData()
{
    SqlDataReader dr = null;
    try
    {
        dc.Open();
        string strSQL = @"SELECT 
			[Doc ID]
			,[Document]
			FROM  
			[dbo].[Document]";


        dr = dc.Read(strSQL);
        if (dr.HasRows)
        {
            dr.Read();

            if (dr["Document"].ToString() != "")
            {
                FCK.Value = System.Text.Encoding.ASCII.GetString((Byte[])dr["Document"]);
            }
        }

    }
    catch (Exception ex)
    {            
    }
    finally
    {
        dc.Close();
    }
}

References

History

  • 12th September, 2012: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) icddr,b
Bangladesh Bangladesh
More than 8 years experience on Programming and Project implementation, I was primarily involved with projects for private organization,Govt.(Bangladesh Army,DG Health,RJSC), NGO (SEDF,WFP). Presently I am working at ICDDR,B and enhancing Hospital Management System developed by Microsoft Dynamic NAV and Windows Mobile Application 5.0

An active supporter of Open Source technology, my interested areas are ERP, IT Audit, Data warehouse, BI etc.

Playing Guitar for 15 years, my interested music style is Blues Rock,Neo Classical.

Certification

70-540:Microsoft® Windows Mobile® 5.0 - Application Development
MB7-514:Microsoft Dynamics™ NAV 5.0 C/SIDE Introduction
MB7-516:Microsoft Dynamics™ NAV 5.0 Solution Development
MB7-517:Microsoft Dynamics™ NAV 5.0 Installation and Configuration
MB7-515:Microsoft Dynamics™ NAV 5.0 Financials
70-432:Microsoft SQL Server 2008 - Implementation and Maintenance
70-450:PRO: Designing, Optimizing and Maintaining a Database Administrative Solution Using Microsoft SQL Server 2008
70-448:Microsoft SQL Server 2008, Business Intelligence Development and Maintenance
312-50:Certified Ethical Hacker

Web :http://masudparvezshabuz.appspot.com
Blog :http://masudparvezshabuz.wordpress.com
linkedin :http://www.linkedin.com/in/masudparvez

Comments and Discussions

 
GeneralMy vote of 1 Pin
nobodyxxxxx14-Sep-12 0:23
nobodyxxxxx14-Sep-12 0:23 
There is absolutly nothing special inside. All you show is a very common way to do this task...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.