将c#对象保存在数据库中 [英] saving c# object in database

查看:96
本文介绍了将c#对象保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个画布,可以在其中生成图像.我想将此画布作为对象保存在数据库中.是否可以在C#中执行?

谢谢
Praveen

I have a canvas in which I generate an image. I want to save this canvas in database as an object. Is it possible to do it in c#?

Thanks
Praveen

推荐答案

如何将对象保存在画布到数据库
将canvas元素上传到webserver/数据库

我希望以上信息对您有所帮助.如果您还有其他疑问,请告诉我.
How to save objects in a Canvas to database
Upload canvas element to webserver/database

I hope the above information will be helpful. If you have more concerns, please let me know.


如果您有图片,那么会有很多文章介绍如何将其添加到数据库中.

C#相册查看器 [
If you have an image there are numerous articles showing how to add it to a database.

C# Photo Album Viewer[^]

Or are you asking how to convert the canvas to an image?


感谢您的反馈.它帮助我解决了我的问题.以下是我选择执行的操作:

将控件转换为xaml并将其存储在数据库中.稍后在需要时,拉出xaml并重新创建控件.

保存到数据库
Thanks for the feedback. It helped me solve my issue. Below is what I opted to do:

Converted the control in to xaml and stored it in database. Later when required, pulled the xaml and recreated the control.

save to database
try
{
    string str = "";
    System.Windows.Controls.Canvas temp = new System.Windows.Controls.Canvas();
    temp = (System.Windows.Controls.Canvas)GraphArea.FindName("CANVASNAME");

    str = XamlWriter.Save(temp);//save the str to database



    GraphArea.Children.Remove(temp);
    GraphArea.UnregisterName(temp.Name);

}
catch (Exception exp)
{

}


结束

从数据库中提取数据并重新创建控件


End

Pull data from database and recreate the control

String strName = "";
  str = "";//pull XAML data from database
  System.Windows.Controls.Canvas canvas = System.Windows.Markup.XamlReader.Load(new System.Xml.XmlTextReader(new System.IO.StringReader(str))) as System.Windows.Controls.Canvas;
  strName = canvas.Name;
  GraphArea.Children.Add(canvas);
  GraphArea.RegisterName(strName, canvas);


结束


解决方案2是我选择的.

http://forums.silverlight.net/forums/p/65180/160429.aspx [


Praveen


End


Solution 2 is what I opted for.

http://forums.silverlight.net/forums/p/65180/160429.aspx[


Praveen


这篇关于将c#对象保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆