Hi everyone... I am developing this student management system which has one form
that saves student data( including student image). Now w.r.t saving student image
I want that the user should insert image from the folder where he has saved student
images. On the save button the image path of the image should be saved in database
(MSSQL). On view record I have added a form having datagridview displaying details.

I want to sync the imagepath in database with the corresponding image in the set folder.
Also pls explain this concept of Memorystream for retrieving image.

Any other suggestion is welcome...

I am a little confused with what you are trying to do so bare with the questions:
1) How are they entering the image onto your form? drag drop or opening a file dialogue?
2) Are you passing the string of the saved file to the database? if so you will have to proceed the saved string with the @ symbol so that the / (folder separator) else this will be removed.
Let me have some more details.

1) I am using a OpenFileDialog Box to add an image
2) How do I send the image path to the database.
Pls check the below code

string imgpath;
imgpath = openDlg.FileName;

Will this do ?

com.Parameters.Add("@imagepath", SqlDbType.NVarChar).Value = @imgpath;

How about if i save the image to a custom created folder ( possibly project folder created at run time) using a Save dialogbox and then save/retrieve the image. This will also ensure that if the folder (where the user has saved the student's image) gets deleted the data will still be there.

Hi, I used the following to display the file path in a label for a club membership system that I once wrote:

lblImage.Text = dlg.FileName;

so it looks like you have the right idea here. for your :

com.Parameters.Add("@imagepath", SqlDbType.NVarChar).Value = @imgpath;

I use the following:

command.Parameters.AddWithValue("P_ImageID", FileAddress);

This is because I have already passed the string to it before. So yeah I think what you have will be spot on.
Secondly I think you should be automatically saving the image to a saved directory. For exactly the same reason that you have suggested. What I would do would be when you save the details for the person; get the referenceID and then pass that back to the form so that you can save the file. using the

SELECT LAST_INSERT_ID();

at least in Mysql. However this would then require another update to the database. Hope this helps.
/*Taylby*/

please explain me about the ReferenceID.. I mean how do I get a Reference ID for a form

After doing a lot of internet searching, I found out this concept of Memorystream which we can use to retrieve the image path..

which one would you suggest, referenceID or memorystream will fulfill my concern..??

I wasn't meaning the reference ID for the form. I was meaning for the student that you are saving data about.
You have your files saved locally when you add them to your form. Such as in the folder on the local path c:/studentSystem/Images then the file name such as Prashant.jpg. Obviously saving them locally will as you have noted potentially cause problems. Therefore I assume in your database you have a primary key for your studnet. as well as other information such as:

Person | CREATE TABLE `person` (
`PersonId` int(11) NOT NULL auto_increment,
`RegistrationDate` date NOT NULL,
`PrefixID` int(11) NOT NULL,
`FirstName` varchar(20) NOT NULL,
`SurName` varchar(20) NOT NULL,
`SexID` int(11) NOT NULL,
`dob` date NOT NULL,
`HouseNo` int(11) NOT NULL,
`AddLine1` varchar(50) NOT NULL,
`AddLine2` varchar(50) NOT NULL,
`AddLine3` varchar(50) NOT NULL,
`TownCity` varchar(50) NOT NULL,
`County` varchar(50) NOT NULL,
`PostCode` varchar(20) NOT NULL,
`EveTelNumber` varchar(20) NOT NULL,
`DayTelNumber` varchar(20) NOT NULL,
`email` varchar(50) default NULL,
`QuestionText` varchar(100) default NULL,
`HearAboutPeakPursuits` varchar(250) default NULL,
`ImageID` varchar(200) default NULL,
PRIMARY KEY  (`PersonId`),
KEY `PrefixID` (`PrefixID`),
KEY `person_ibfk_1` (`SexID`),
CONSTRAINT `person_ibfk_1` FOREIGN KEY (`SexID`) REFERENCES `sex` (`SexID`)
ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=latin1 |

Now I have the ImageID which is the file location for that person. Therefore by retrieving the persons ID you could then save a copy of the file instead of Prashant.jpg but as their ID Number such as 05292862.jpg on a centralised document server. This will reduce the likelihood of two people having the same name wanting to have a file named after that. Hope that helps but do let me know if you have questions. As for the MemeoryStream which is used to read/write data an array. you will be using the OS's native way to save data. Therefore let it do this. you just need to save the images location and name.
--Taylby

This seems an easy and logical way THANX !!. This will help me save my image with a unique filename.


In the form image( in my first post), there's one VIEW RECORD button which open's a new form having DataGridView(below image). What I am trying to do is that get the detail of a student on form by selecting a General Register No.(GR No.) which is a unique key(primary key). The idea is to keep the imagepath column as hidden and retrieve the details along with the image based on that value. I am using the following code to upload the details of the Datagrid onto form

frmStudent frmStud = new frmStudent(dgvstudisplay.CurrentRow.Cells[0].Value.ToString());
                
                frmStud.Show();
                Close();

How do I synchronise the imagepath field in Datagridview to picturebox ?
please suggest me any other idea you would like to refer ?

Hi have you resolved this yet? Or are you still needing some guidance? I have been away.
--Taylby

I have exactly the same question, where I cannot retrieve images. I know how to retrieve text but not images. have you resolved the problem?

hi angele18..
did u mean retrieveing text from image and saving to database...??
these r 2 different concepts!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.