gpt4 book ai didi

c# - 使用 C# 从数据库中保存和检索 rtf 文本

转载 作者:行者123 更新时间:2023-11-29 21:04:10 25 4
gpt4 key购买 nike

我刚刚完成将 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。

最佳答案

快速搜索就会找到答案。例如,这里是一些查询数据库表的示例代码...

// 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 ,但是还有数百万个其他网站可以教您这些东西。

关于c# - 使用 C# 从数据库中保存和检索 rtf 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36969224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com