In your web service add the following:
[WebMethod]
public int SaveImage(Byte[] imgdata)
{
//use the web.config to store the connection string
SqlConnection connection = new SqlConnection("YourConnectionString");
//build the SQL command
//Put your insert statement here--the "Image" column needs to
//be of type "image"
SqlCommand command = new SqlCommand( "INSERT INTO ContactsImages
(ImageData) VALUES (@img_data )", connection );
//build the parameters
command.Parameters.Add(new SqlParameter("@img_data", imgdata));
//open the datbase connection
try
{
//if the DB connection is not already open, open it
if(connection.State != ConnectionState.Open)
{
connection.Open();
}
}
catch
{
//can't open the conenction to the database--throw an error
Exception oException= new Exception("An error occured while opening
connection to the database.");
throw oException;
}
//perform the sql command and store the results
int numRowsAffected = command.ExecuteNonQuery();
//close the database connection
connection.Close();
//answer with the number of rows - 1 if successful
return numRowsAffected;
}
Then in your windows application add a "web refrence" to the web
service and use code like the following:
private void btnUpload_Click(object sender, System.EventArgs e)
{
String strBLOBFilePath = textBox1.Text; //textbox with name and path
to image
FileStream fsBLOBFile = new
FileStream(strBLOBFilePath,FileMode.Open, FileAccess.Read);
Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
fsBLOBFile.Close();
MYWEBSERVICE.MYSERVICENAME IDS = new MYWEBSERVICE.MYSERVICENAME();
int Output = IDS.SaveImage(bytBLOBData);
}
The key is to convert the image to a byte[] array before you send it.
Hope someone else finds this useful.
What is the error or the issue you are running into specifically?
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Eric Paul" <erical...@hotmail.com> wrote in message
news:658d9a02.04030...@posting.google.com...
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote in
message news:uYjWP9TB...@TK2MSFTNGP12.phx.gbl...