0

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.

egrunin
  • 24,650
  • 8
  • 50
  • 93
Croviajo
  • 253
  • 1
  • 8
  • 17

1 Answers1

1

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>);
Community
  • 1
  • 1
HichemSeeSharp
  • 3,240
  • 2
  • 22
  • 44