AJAX EDITOR IN ASP.NET

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 778  View(s)
Ratings:
Rate this:

I have an Ajax Editor in my page:

<cc1:Editor ID="Editor1" runat="server" width="600px"/>

What I want is to save the content from the Editor to my database.I tried this but it won't work:

SqlCommand cmd = new SqlCommand(

    "INSERT INTO titlu (descriere) Values(@descriere)",con);

cmd.Parameters.AddWithValue("@descriere", Editor1.Content);

I am using C# and it's a ASP.Net web application.. Why can't I save my data?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: ajax editor in ASP.NET

    Hi Ankita, 

    try this:

      using (SqlConnection connection =

                   new SqlConnection(connectionString))

        {

            try

            {

                int count = 0;

                SqlCommand command = new SqlCommand(commandText, connection);

                connection.Open();

                IAsyncResult result = command.BeginExecuteNonQuery();

                while (!result.IsCompleted)

                {

                    Console.WriteLine("Waiting ({0})", count++);

                    // Wait for 1/10 second, so the counter

                    // does not consume all available resources

                    // on the main thread.

                    System.Threading.Thread.Sleep(100);

                }

                Console.WriteLine("Command complete. Affected {0} rows.",

                    command.EndExecuteNonQuery(result));

            }

            catch (SqlException ex)

            {

                Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message);

            }

            catch (InvalidOperationException ex)

            {

                Console.WriteLine("Error: {0}", ex.Message);

            }

            catch (Exception ex)

            {

                // You might want to pass these errors

                // back out to the caller.

                Console.WriteLine("Error: {0}", ex.Message);

            }

        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!