Advertise with us

ajax editor in ASP.NET

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?

Last updated:8/22/2014 2:01:04 AM

1 Answers

Sumit Kesarwani
Sumit Kesarwani

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)
        {
            // Youmight want to pass these errors
            // backout to the caller.
            Console.WriteLine("Error:{0}", ex.Message);
        }
    }

Answer