使用 Oracle Blob 在 C# 中加载图片框
我有一个非常基本的表单,只有一个图片框、一个文本字段和一个按钮。我在 Oracle 中创建了一个表来存储 blob,我想在单击按钮后将该图像加载到 c# 中的图片框中。这是我到目前为止所写的内容。
我的图片框名称=“picBoxXray”。我的文本框名称=“txtXrayId”。我的按钮名称 =“btnGetXrayID”。我的表名称是“XRay”。
private void btnGetXrayID_Click(object sender, EventArgs e)
{
if (txtXrayId.Text == "")
{
MessageBox.Show("XrayID be entered");
}
if (picBoxXray.Image != null)
{
picBoxXray.Image.Dispose();
}
string connectionString = GetConnectionString();
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
OracleCommand command = connection.CreateCommand();
string sql = "SELECT * FROM XRay WHERE XrayID =" + txtXrayId.Text;
OracleCommand cmd = new OracleCommand(sql, connection);
OracleDataReader dr = cmd.ExecuteReader();
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
while (dr.Read())
{
// Obtain the image
//Need code
}
command.CommandText = sql;
command.ExecuteNonQuery();
connection.Close();
}
任何帮助将不胜感激, 谢谢
I've a very basic form with just one picture box,one textfield and one button. I've created a table in Oracle to store a blob, I want to load that image into a picturebox in c# once the button is clicked. Here is what I've wrote so far.
My picturebox name = "picBoxXray". My textbox name = "txtXrayId". My button name = "btnGetXrayID". And My table name is "XRay".
private void btnGetXrayID_Click(object sender, EventArgs e)
{
if (txtXrayId.Text == "")
{
MessageBox.Show("XrayID be entered");
}
if (picBoxXray.Image != null)
{
picBoxXray.Image.Dispose();
}
string connectionString = GetConnectionString();
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
OracleCommand command = connection.CreateCommand();
string sql = "SELECT * FROM XRay WHERE XrayID =" + txtXrayId.Text;
OracleCommand cmd = new OracleCommand(sql, connection);
OracleDataReader dr = cmd.ExecuteReader();
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
while (dr.Read())
{
// Obtain the image
//Need code
}
command.CommandText = sql;
command.ExecuteNonQuery();
connection.Close();
}
Any help would be greatly aprreciated,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须从流创建图像,例如:
然后将图像分配给图片框。其中的 byteArray 是您从数据库读取的 blob。当然,图像必须以已知的格式存储(例如 png/jpeg )
You have to create the image from a stream, for example:
Then aassign the image to the picture box. the byteArray in is the blob you read from the db. of course the image have to be stored in a format known ( png/jpeg for instance )