I have a C# program that stores images in "H:\oucu\Student Photos", and supposedly to an SQL database, in one of eight tables. the file saves well, but I try to use a web application to read the images, every information in the row appears except the images.
public bool SaveDIBAs( string picname, IntPtr bminfo, IntPtr pixdat )
{
string Partion= @"h:\oucu\Student_Images\";
string StName=St_num;
string FullPath=Partion+StName;
Guid clsid;
if( ! GetCodecClsid( FullPath.ToString(), out clsid ) )
{
MessageBox.Show( "Unknown picture format for extension " + Path.GetExtension( FullPath.ToString() ),
"Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information );
return false;
}
IntPtr img = IntPtr.Zero;
int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img );
if( (st != 0) || (img == IntPtr.Zero) )
return false;
textBox2.Text = FullPath.ToString() ;
st = GdipSaveImageToFile( img,FullPath.ToString(), ref clsid, IntPtr.Zero );
GdipDisposeImage( img );
return st == 0;
}
public void ShowFrm()
{
this.Show();
}
private void button1_Click(object sender, System.EventArgs e)
{
St_num = StudentPhoto.photo.fileName;
SaveDIBAs( this.Text, bmpptr, pixptr );
byte[] byte_Img;
SqlConnection mySqlConn = new SqlConnection("server=192.168.1.25;workstation id=localhost;packet size=4096; persist security info=False;user id=araslan;Password=hR@oucu1;Initial catalog=mandoobeen;min pool size=1;max pool size=10000000;connection lifetime=6000");
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection=mySqlConn;
sqlcmd.CommandText="insert into " + StudentPhoto.photo.tableName + " (nationalNumber,pictureName,Picture) values(@nN,@pN,@pic)";
sqlcmd.Parameters.Add("@nN",System.Data.SqlDbType.NVarChar);
sqlcmd.Parameters.Add("@pic",System.Data.SqlDbType.Image);
sqlcmd.Parameters.Add("@pN",System.Data.SqlDbType.NVarChar);
FileStream fs=new FileStream(this.textBox2.Text.ToString(),FileMode.Open,FileAccess.Read,FileShare.Read);
byte_Img=new byte[Convert.ToInt32(fs.Length)];
int iBytesRead=fs.Read(byte_Img,0,Convert.ToInt32(fs.Length));
fs.Close();
sqlcmd.Parameters["@nN"].Value = StudentPhoto.photo.nationalNumber;
sqlcmd.Parameters["@pic"].Value=byte_Img;
TwainGui.Login l = new TwainGui.Login();
sqlcmd.Parameters["@pN"].Value = StudentPhoto.photo.fileName;
mySqlConn.Open();
int iresult=sqlcmd.ExecuteNonQuery();
mySqlConn.Close();
System.Diagnostics.Process process1;
process1= new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
Directory.SetCurrentDirectory(textBox3.Text);
Application.Exit();
}