PDA

View Full Version : سوال: تبدیل باینری به رشته



f_naderi
یک شنبه 07 شهریور 1395, 12:30 عصر
سلام دوستان.
من داخل برنامم از دیتابیس access استفاده کردم و نوع فیلد ole object است. محتویات فایل ورد رو ذخیره کردم توی فیلد QTS حالا برای بازیابیش این کد رو نوشتم:

object path = (Object)System.Windows.Forms.Application.StartupPa th + "\\1.docx"; object read = "ReadWrite";
object readOnly = false;
object o = System.Reflection.Missing.Value;
Class1.str1 = "select top 1 Qts from Quastion where l_code=" + Convert.ToInt32(comboBox3.SelectedValue);
Class1.da = new System.Data.OleDb.OleDbDataAdapter(Class1.str1, Class1.con);
Class1.da.Fill(Class1.dsclass);
Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application(); ;
object oMissing = Type.Missing;
oWord.Visible = true;
oWord.Documents.Open(ref path, ref o, ref readOnly, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
byte[] bytes = (byte[])Class1.dsclass.Tables[0].Rows[0][0];
string text = BitConverter.ToString(bytes);
//string text = Encoding.Unicode.GetString(bytes);
//int numberChars = text.Length;
//byte[] b = new byte[numberChars / 2];
//for (int i = 0; i < numberChars; i += 2)
//{
// b[i / 2] = Convert.ToByte(text.Substring(i, 2), 16);
//}
//string StrValue= Encoding.Unicode.GetString(b);
oWord.Selection.TypeText(text);
محتویات رو داخل فایل ورد به این صورت نشون میده:53-00-79-00-73-00-74-00-65-00-6D-00-2E-00-42-00-79-00-74-00-65-00-5B-00-5D-00

و اگه کد رو به این صورت بنویسم :

object path = (Object)System.Windows.Forms.Application.StartupPa th + "\\1.docx";
object read = "ReadWrite";
object readOnly = false;
object o = System.Reflection.Missing.Value;
Class1.str1 = "select top 1 Qts from Quastion where l_code=" + Convert.ToInt32(comboBox3.SelectedValue);
Class1.da = new System.Data.OleDb.OleDbDataAdapter(Class1.str1, Class1.con);
Class1.da.Fill(Class1.dsclass);
Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application(); ;

object oMissing = Type.Missing;

oWord.Visible = true;
oWord.Documents.Open(ref path, ref o, ref readOnly, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
byte[] bytes = (byte[])Class1.dsclass.Tables[0].Rows[0][0];
//string s = BitConverter.ToString();
string text = Encoding.Unicode.GetString(bytes);
oWord.Selection.TypeText(text);

محتویات داخل دیتابیس رو بدین صورت نمایش میده: system.byte[]
ممنون میشم راهنمایی بفرمایی

mr.sirwan
یک شنبه 07 شهریور 1395, 13:39 عصر
سلام دوست عزیز، پاسختون رو توی سوال قبلیتون دادم :لبخندساده::لبخندساده: