System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection();
Conn.ConnectionString = "Data Source=(Local);Initial Catalog=MyTest;User ID=sa";
Conn.Open();
System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
Cmd.Connection = Conn;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter S_Format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream S_Stream = new System.IO.MemoryStream();
S_Format.Serialize(S_Stream, pictureBox1.Image);
byte[] TmpByte = new byte[S_Stream.Length];
S_Stream.Seek(0, System.IO.SeekOrigin.Begin);
S_Stream.Read(TmpByte, 0, (Int32)S_Stream.Length);
S_Stream.Close();
MessageBox.Show(TmpByte.Length.ToString());
string TmpGuid = System.Guid.NewGuid().ToString();
Cmd.CommandType = CommandType.Text;
Cmd.CommandText += "INSERT INTO MyTest.dbo.img(id,thing) VALUES('" + TmpGuid + "',@Test)" + "/r/n";
Cmd.CommandText += "SELECT * FROM MyTest.dbo.img WHERE id='" + TmpGuid + "'" + "/r/n";
Cmd.Parameters.Add("@Test",SqlDbType.Image);
Cmd.Parameters["@Test"].Value = TmpByte;
System.Data.SqlClient.SqlDataReader TmpRead = Cmd.ExecuteReader() as System.Data.SqlClient.SqlDataReader;
TmpRead.Read();
MessageBox.Show(TmpRead[0].ToString() + " Finish");
byte[] GetTmpByte = TmpRead[1] as byte[];
MessageBox.Show(GetTmpByte.Length.ToString());
System.IO.MemoryStream MemStream = new System.IO.MemoryStream();
MemStream.Write(GetTmpByte, 0, GetTmpByte.Length);
MemStream.Seek(0, System.IO.SeekOrigin.Begin);
pictureBox2.Image = S_Format.Deserialize(MemStream) as System.Drawing.Image;
Cmd.Dispose();
Conn.Close();
Conn.Dispose();