Save array to DB

Reply

Join Date: May 2009
Posts: 24
Reputation: krokodajl is an unknown quantity at this point 
Solved Threads: 0
krokodajl krokodajl is offline Offline
Newbie Poster

Save array to DB

 
0
  #1
Aug 12th, 2009
Hi

my question is about saving array consisting of elements of type UIElement or Button. How can I store them in database and read them from db? Must I conert array to any other type(conversion from UIElement to Byte raises errors). What type column od db should have to store this array?

regards
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,803
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 681
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: Save array to DB

 
0
  #2
Aug 12th, 2009
Choose Image/varbinary/blob/ole column (field) datatype.
Write byte array,
  1. byte []b=.....
  2. System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection();
  3. System.Data.OleDb.OleDbCommand cmd=new System.Data.OleDb.OleDbCommand("insert into tableName values (col1)", cn);
  4.  
  5. cmd.Parameters.Add("col1",System.Data.OleDb.OleDbType.Binary,b.Length,"col1");
  6. cmd.Parameters[0].Value= b;
  7.  
  8. cn.Open();
  9. cmd.ExecuteNonQuery();
  10. cn.Close();
Read,
  1. ...
  2. cmd=new System.Data.OleDb.OleDbCommand("select * from tableName",cn);
  3. System.Data.OleDb.OleDbDataReader dr;
  4. dr=cmd.ExecuteReader();
  5. while(dr.Read())
  6. {
  7. byte []t=(byte [])dr[0];
  8. ....
  9. }
  10. dr.Close();
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 24
Reputation: krokodajl is an unknown quantity at this point 
Solved Threads: 0
krokodajl krokodajl is offline Offline
Newbie Poster

Re: Save array to DB

 
0
  #3
Aug 12th, 2009
thanks

but the problem is in converting array elements from UIElement to byte. .. It raises error
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,803
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 681
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: Save array to DB

 
0
  #4
Aug 12th, 2009
Type UIElement must be serializable. Use binary serialization.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 24
Reputation: krokodajl is an unknown quantity at this point 
Solved Threads: 0
krokodajl krokodajl is offline Offline
Newbie Poster

Re: Save array to DB

 
0
  #5
Aug 12th, 2009
could you explain me how can I do that?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,803
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 681
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: Save array to DB

 
0
  #6
Aug 12th, 2009
  1. [Serializable]
  2. public class Test
  3. {
  4.  
  5. }
  6. class MainA
  7. {
  8. static void Main()
  9. {
  10. Test a = new Test();
  11. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  12. System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bs = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  13. bs.Serialize(ms, a);
  14.  
  15. byte[] b = ms.ToArray();
  16. Console.WriteLine(b.Length);
  17. }
  18. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 345 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC