Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone
im creating windows mobile application i want to save image in sqlcompact and this is my code
OpenFileDialog fd = new OpenFileDialog();
            fd.Filter="jpg file (*.jpg)|*.jpg";
            if (fd.ShowDialog() == DialogResult.OK)
            {
                string sd = fd.FileName.ToString();
                pictureBox1.Image = sd;
            
            }

i know when i use windows application i use
string sim=opf.filename.tostring();
pictureBox.imagelocation= sim
,,,,,it work fine
but with mobile application we don't have imagelocation propriety
so any suggestion will be appreciated ....
Posted
Comments
Vamshi Krishna Naidu 18-Mar-15 15:01pm    
Do you have ImageSource???
Joan Magnet 19-Mar-15 19:19pm    
Is this useful for you?
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/aa25aa9b-17d2-4724-806f-17ec4b871119/how-to-insert-image-into-sql-server-manually-without-code?forum=sqlgetstarted

1 solution

using System.Data.SqlServerCe;

private void updatedata()
{
try
{
if (imagename != "")
{
FileStream fs;
byte[] picbyte;
using(fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read))
{
//a byte array to read the image
picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
}
string connstr = @"Data Source=.\TestImage.sdf;Persist Security Info=False;"
string query = "insert into test_table(id_image,pic) " +
"values(@id, @pic)";
using(SqlCeConnection conn = new SqlCeConnection(connstr))
using(SqlCeCommand cmd = new SqlCeCommand(query, conn))
{
conn.Open();
SqlCeParameter picparameter = new SqlCeParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName = "pic";
picparameter.Value = picbyte;
cmd.Parameters.Add(picparameter);
SqlCeParameter idparameter = new SqlCeParameter();
idparameter.SqlDbType = SqlDbType.Int;
idparameter.ParameterName = "id";
idparameter.Value = textBox1.Text;
cmd.Parameters.Add(idparameter);
cmd.ExecuteNonQuery();
MessageBox.Show("Image Added");
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900