954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PictureBox/Image - Stored to SQL Database

Hello My Friends,

I have a question...
How can i add a photo/picture into SQL Server 2000....?

Need advice please.

fauzanf
Newbie Poster
6 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

Hi Fauzan

The short answer is "you can't" as SQL only handles text, not images.

You can however create a table in SQL where you put the links to all the image files. Then in your report you can link the data that you want with that text link. You then take that text output from SQL, and through the formatting of your report you can use that retrieved link to load the picture.

m_coombes
Newbie Poster
5 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

ok,

so... do you have a sample code?

fauzanf
Newbie Poster
6 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

ok,

so... do you have a sample code?

That depends on your interface. If you are using pure SQL, just use a standard "INSERT" command.

The link to the MSDN article that explains it is here http://msdn.microsoft.com/en-us/library/h54fa37c(VS.80).aspx

m_coombes
Newbie Poster
5 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 
aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

Hi Fauzan

The short answer is "you can't" as SQL only handles text, not images.

You can however create a table in SQL where you put the links to all the image files. Then in your report you can link the data that you want with that text link. You then take that text output from SQL, and through the formatting of your report you can use that retrieved link to load the picture.

You really should follow up with that the long answer is that you can but this is the preferred method by many, that is just to store the path to the file in the database and not the file itself. And just for you information there are a couple of ways to do it.

OP. Use the Data Form Wizard, which you will find under Add-Ins>Add-In Manager and use the ODBC option which means before you use it you will have to create an ODBC DSN. Use each form option in combination with code/class/control and save project for future use. Then once you are ready to go to a DNS Less connection see http://www.connectionstrings.com


Good Luck

vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

hi friend you can easily save an photo and image to the database. check out this code

private void button1_Click(object sender, EventArgs e)
{

OpenFileDialog dlg = new OpenFileDialog();

dlg.Title = "Open Photo";

if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox1.Image = new Bitmap(dlg.OpenFile());

name = dlg.FileName;
txtname.Text = dlg.SafeFileName;
}
catch (Exception ex)
{
MessageBox.Show("Unable to load file: " + ex.Message);
}
}

dlg.Dispose();
}

karthikvcsharp
Newbie Poster
2 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Wrong forum K, that is .NET code and this is the "classic" Visual Basic forum!

vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You