Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET中的ajax编辑器_C#_Asp.net_Ajax - Fatal编程技术网

C# ASP.NET中的ajax编辑器

C# ASP.NET中的ajax编辑器,c#,asp.net,ajax,C#,Asp.net,Ajax,我的页面中有一个Ajax编辑器: <cc1:Editor ID="Editor1" runat="server" width="600px"/> 我正在使用C#,它是一个ASP.Net web应用程序。。为什么我不能保存数据?您的代码没有显示执行SQL命令的位置。如果执行命令什么 您得到了错误代码或异常吗 请参见此示例: // Given command text and connection string, asynchronously execute // the s

我的页面中有一个Ajax编辑器:

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

我正在使用C#,它是一个ASP.Net web应用程序。。为什么我不能保存数据?

您的代码没有显示执行SQL命令的位置。如果执行命令什么 您得到了错误代码或异常吗

请参见此示例:

 // Given command text and connection string, asynchronously execute
    // the specified command against the connection. For this example,
    // the code displays an indicator as it is working, verifying the 
    // asynchronous behavior. 
    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);
        }
    }

假设您的代码是这样的:

using (SqlConnection con = new ...)
{
    SqlCommand cmd = new SqlCommand(
                    "INSERT INTO titlu (descriere) Values(@descriere)",con);
    cmd.Parameters.AddWithValue("@descriere", Editor1.Content);
    con.Open();
    int affectedRows = cmd.ExecuteNonQuery();
}
然后,行
cmd.ExecuteNonQuery()
将抛出异常或返回受影响的行数-在您的情况下,它显然应该是1


如果未引发异常,则该值将输入数据库-确保在此处访问Editor1.Content时,它确实包含某些内容。另外,请确保您没有接受异常。

启动调试器-进入调试器-如果您看不出有什么错误,请将代码张贴到与您期望的行为不同的地方。这是它行为不同的部分。我无法从编辑器中获取值并将其插入数据库
using (SqlConnection con = new ...)
{
    SqlCommand cmd = new SqlCommand(
                    "INSERT INTO titlu (descriere) Values(@descriere)",con);
    cmd.Parameters.AddWithValue("@descriere", Editor1.Content);
    con.Open();
    int affectedRows = cmd.ExecuteNonQuery();
}