Reputation: 249
I'm want to save an image to a sql server DB by using it's path, that i don't want to save the image it self i just want when i upload an image to my form and when i click in a button this button upload the image to the application folder then save the path of this picture to the databasen, How can I do that ?
2 - how can i add this picture to a dataGridView ?
NOTE : I'm using C# as a programming language.
Upvotes: 0
Views: 1681
Reputation: 3318
Getting the image file path can be done using OpenFileDialog.
This answer can help you getting file path Extracting Path from OpenFileDialog path/filename
1) You can copy them using File.Copy(path, path2)
function to your app directory :
string path = Directory.GetCurrentDirectory();
2) You need to use Bitmap to get your image loaded from its file path :
Bitmap myBmp = Bitmap.FromFile("path here");
And then you can add it to a DataGridView
assuming that contains DataGridViewImageColumn
yourDataGridView.Rows.Add(<column1 value>, <column2 value>, myBmp, <column3 value>, <column4 value>);
Upvotes: 1