【问题标题】:Save and retrive rtf text from database using c#使用 c# 从数据库中保存和检索 rtf 文本
【发布时间】:2016-08-26 10:30:50
【问题描述】:

我刚刚完成了将richtextbox 中的文本保存到sql 数据库中。这里有代码:

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
        con.Open();
        SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[FISIER] (File_name,The_text) VALUES (@File_name,@The_text)", con);
        cmd.Parameters.Add("@File_name", textBox1.Text);
        cmd.Parameters.AddWithValue("@The_text", richTextBox1.Rtf);
        cmd.ExecuteNonQuery();
        con.Close();
    }

这是Click here for table的表格

现在,我的问题是我不知道如何从数据库中检索文本。如您所见,我保存到The_text 中的文本是Text。我想将数据检索回richtextbox。

【问题讨论】:

    标签: c# mysql sql-server database


    【解决方案1】:

    快速搜索就会发现这个问题的答案。例如,下面是一些查询数据库表的示例代码...

    // 1. Instantiate a new command with a query and connection
    SqlCommand cmd = new SqlCommand("select CategoryName from Categories", conn);
    
    // 2. Call Execute reader to get query results
    SqlDataReader rdr = cmd.ExecuteReader();
    

    您可以更改表名和字段以匹配您的数据库。

    此代码可在 http://www.csharp-station.com/Tutorial/AdoDotNet/Lesson03 找到,但还有数百万其他网站会教您这些东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 2021-05-07
      • 1970-01-01
      相关资源
      最近更新 更多