【发布时间】:2022-01-20 19:38:03
【问题描述】:
我正在尝试将数据转换为 RichTextBox,但仍然无法做到。下面是我的代码。我的数据测试并有数据,现在只需将其读入RichTextBox。
private void btnConvert_Click(object sender, EventArgs e)
{
ListViewItem selectedComune = lvResultCommune.SelectedItems[0];
string selectedCommuneId = selectedComune.Text;
if (selectedCommuneId != null)
{
NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
NpgsqlCommand cmd = new NpgsqlCommand("SELECT ST_AsText(geom) as geometry FROM hanhchinhxa where id_4 = " + selectedCommuneId , conn);
adapter.SelectCommand = cmd;
cmd.Connection = conn;
DataTable data = new DataTable();
adapter.Fill(data);
richTextBox.Text = data.ToString();
}
else
{
throw new Exception("\n" + "Geometry illegal !!");
}
}
【问题讨论】:
-
尝试将其转换为 Base 64 字符串并将其设置在文本框中,每次都对我有用!
-
如何转换? @runtimeTerror
-
请不要使用字符串连接来创建sql命令,你正在打开自己对Sql Injection攻击的开放。
-
别担心,我只是在尝试得到结果
-
richTextBox.Text = data.ToString();... 并没有按照您的想法行事。data是DataTable... 它有行和列。
标签: c# postgresql