Getting error after updating image in Sql server 2008 database - c#

I am developing a winform application in VS 2010 C#.
I have developed a form to insert and update the user details in this.
My Update user form is as below image
![Update User Screen][1]
http://i.stack.imgur.com/iZaAJ.png
And coding to update is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Drawing.Imaging;
using System.IO;
namespace SampleApplication
{
public partial class UserUpdate : Form
{
public UserUpdate()
{
InitializeComponent();
}
SqlDataAdapter da;
SqlConnection con = new SqlConnection("user id=sa; password=123;initial catalog=Inventory;data source=Aniket-PC");
SqlCommand cmd;
MemoryStream ms;
byte[] photo_array;
DataSet ds;
int rno = 0;
string str;
private void nameTxt_Validating(object sender, CancelEventArgs e)
{
if (nameTxt.Text.Trim().Length == 0)
{
namewarning.Visible = true;
}
else
{
namewarning.Visible = false;
}
}
private void Update_Load(object sender, EventArgs e)
{
contTxt.MaxLength = 10;
retriveData();
retriveImg();
}
void retriveImg()
{
con.Open();
cmd = new SqlCommand("Select Logo from Register where UserName='" + uNameTxt.Text + "'", con);
da = new SqlDataAdapter(cmd);
ds = new DataSet("MyImage");
da.Fill(ds, "MyImage");
DataRow myRow;
myRow = ds.Tables["MyImage"].Rows[0];
photo_array = (byte[])myRow["Logo"];
ms = new MemoryStream(photo_array);
profPic.Image = Image.FromStream(ms);
con.Close();
}
void retriveData()
{
con.Open();
cmd = new SqlCommand("Select * from Register where UserName='"+uNameTxt.Text+"'",con);
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
nameTxt.Text = (read["Name"].ToString());
passTxt.Text = (read["Password"].ToString());
conPassTxt.Text = (read["Password"].ToString());
emailTxt.Text = (read["EmailId"].ToString());
addTxt.Text = (read["Address"].ToString());
contTxt.Text = (read["ContactNo"].ToString());
DORTxt.Text = (read["DOR"].ToString());
validity.Text = "Account Valid till "+(read["Validity"].ToString());
}
read.Close();
con.Close();
}
private void AttachBtn_Click(object sender, EventArgs e)
{
// Open image by OpenFiledialog and show it in PicturBox.
try
{
//filter only image format files.
openFileDialog1.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
DialogResult res = openFileDialog1.ShowDialog();
if (res == DialogResult.OK)
{
Image img = new Bitmap(openFileDialog1.FileName);
//inserting image in PicturBox
profPic.Image = img.GetThumbnailImage(127, 128, null, new IntPtr());
openFileDialog1.RestoreDirectory = true;
}
}
catch
{
MessageBox.Show("Cannot upload image");
}
}
private void UpdateBtn_Click_1(object sender, EventArgs e)
{
string DOM = dateTimePicker1.Value.ToShortDateString();
if (namewarning.Visible == true || picError.Visible == true || PassError.Visible == true || emailwarningImg.Visible == true)
{
MessageBox.Show("Please correct the marked fields");
}
else
{
//cmd = new SqlCommand("update Register set (Name,Password,EmailId,Address,ContactNo,Logo,DOM) values('" + nameTxt.Text.Trim() + "','" + passTxt.Text.Trim() + "','" + emailTxt.Text.Trim() + "','" + addTxt.Text.Trim() + "','" + contTxt.Text.Trim() + "',#Logo,'" + DOM+ "')", con);
str = string.Format("update Register set Name='{0}', Password='{1}',EmailID='{2}',Address='{3}',ContactNo='{4}',Logo='{5}',DOU='{6}' where UserName='{7}'", nameTxt.Text.Trim(), passTxt.Text.Trim(), emailTxt.Text.Trim(),addTxt.Text.Trim(), contTxt.Text.Trim(), #"Logo" ,DOM,uNameTxt.Text);
con_photo();
//con.Open();
cmd = new SqlCommand(str, con);
int count= cmd.ExecuteNonQuery();
if (count > 0)
MessageBox.Show("Sucsess");
else
MessageBox.Show("need to work");
}
}
void con_photo()
{
if (profPic.Image != null)
{
ms = new MemoryStream();
profPic.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_array = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_array, 0, photo_array.Length);
cmd.Parameters.AddWithValue("#Logo", photo_array);
}
}
when i run the application it executes very well and shows me success message but when i again try to view the update user form it shows below screenshot error
http://i.stack.imgur.com/7z1Rx.png
at retriveImg ()
Please help me with resolution for this..

You're not passing the image bytes to the UPDATE command, but a string containing the word Logo.
Also: PLEASE avoid creating SQL commands using string concatenation or String.Format. Use parameterized queries instead!
Also: Do not use an NVARCHAR field to store the image bytes (unless you create a BASE64 string from them first), but use a VARBINARY or IMAGE column instead.
The problem is in the following line:
str = string.Format("update Register set ... ,Logo='{5}' ...", ..., #"Logo", ...);
As you can see, you're formatting a string, but you don't insert the bytes from the image, but the word "Logo".
Assuming the column Logo was of type IMAGE or VARBINARY, I would write something like this:
byte[] photo_array = null;
if (profPic.Image != null)
{
MemoryStream ms = new MemoryStream();
profPic.Image.Save(ms, ImageFormat.Jpeg);
photo_array = ms.GetBuffer();
}
if (photo_array != null)
{
SqlCommand cmd = new SqlCommand("UPDATE Register SET Logo=#logo", connection);
cmd.Parameters.AddWithValue("#logo", imageBytes);
cmd.ExecuteNonQuery();
}

Maybe I'm wrong but I'll try to do this
photo_array = (byte[])myRow["Logo"];
if photo_array.length.trim()>0
{
ms = new MemoryStream(photo_array);
profPic.Image = Image.FromStream(ms);
}
con.Close();
This error may come when the lenght of the string is 0
Another thing is that you're not saving the image in the database

//C# Code
SqlCommand cmdSelect = new SqlCommand("select ImageValue from table where ID=1", ObjCon);
ObjCon.Open();
byte[] barrImg = (byte[])cmdSelect.ExecuteScalar();
ObjCon.Close();
string strfn = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream("C:\\Temp\\1.txt", FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
// 1.txt file will be created in c:\temp folder

Related

How to load an image that is stored in a database into a picturebox object with C# and SQL

When doubling clicking a row in datagrid object within the following windows form, the relevant information properly displays in a secondary form.
However I am not sure how to make it so that the image also displays in picturebox within the Student Form.
Here is the code so far:
public bool IsUpdate { get; set; }
private void StudentForm_Load(object sender, EventArgs e)
{
//For Update Process
if (this.IsUpdate == true)
{
using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString()))
{
using (SqlCommand cmd = new SqlCommand("usp_Student_ReloadDataForUpdate", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#StudentName", this.StudentName);
if (con.State != ConnectionState.Open)
con.Open();
DataTable dtStudent = new DataTable();
SqlDataReader sdr = cmd.ExecuteReader();
dtStudent.Load(sdr);
DataRow row = dtStudent.Rows[0];
StudentNameTextBox.Text = row["StudentName"].ToString();
AgeTextBox.Text = row["Age"].ToString();
GenderTextBox.Text = row["Gender"].ToString();
DescriptionTextBox.Text = row["Description"].ToString();
//IdPictureBox.Image = row["Image"].???
SaveButton.Text = "Update Student Information";
DeleteButton.Enabled = true;
}
}
}
This follow is the stored procedure for the method above:
CREATE PROCEDURE usp_Student_ReloadDataForUpdate
(
#StudentName NVARCHAR(200)
)
AS
BEGIN
SELECT [StudentId]
,[StudentName]
,[Age]
,[Gender]
,[Description]
,[Image]
FROM [dbo].[Students]
WHERE StudentName = #StudentName
END
This is how the data is saved in the database
private void SaveButton_Click(object sender, EventArgs e)
{
if(IsFormValid())
{
//Do Update Process
using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method
{
using (SqlCommand cmd = new SqlCommand("usp_Student_InsertNewStudent", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#StudentName", StudentNameTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Age", AgeTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Gender", GenderTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Description", DescriptionTextBox.Text.Trim());
var image = IdPictureBox.Image;
using (var ms = new MemoryStream())
{
image.Save(ms, image.RawFormat);
cmd.Parameters.Add("#Image", SqlDbType.VarBinary).Value = ms.ToArray();
}
cmd.Parameters.AddWithValue("#CreatedBy", LoggedInUser.UserName);
if (con.State != ConnectionState.Open)
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Student is successfully updated in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
ResetFormControl();
}
}
}
The data stored is a byte[] (Varbinary). You should convert it to an Image:
var pic = (byte[])row["Image"];
if (pic != null)
{
using (MemoryStream ms = new MemoryStream(pic))
{
IdPictureBox.Image = Image.FromStream(ms);
}
}
PS: I am not commenting on the rest of your code, like you shouldn't use AddWithValue but Add.

Values from textBox not getting inserted into database C#

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Request.InputStream.Length > 0)
{
using (StreamReader reader = new StreamReader(Request.InputStream))
{
string hexString = Server.UrlEncode(reader.ReadToEnd());
string imageName = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
string imagePath = string.Format("~/losefound/{0}.png", imageName);
string ItemName = txtItemName.Text;
string Place = txtPlace.Text;
byte[] bytes = ConvertHexToBytes(hexString);
File.WriteAllBytes(Server.MapPath(imagePath), bytes);
string VisitorManagementConnectionString = ConfigurationManager.ConnectionStrings["VisitorManagementConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(VisitorManagementConnectionString))
{
string query = "INSERT INTO LostFound (ItemName, FoundAt, TimeIn, ImageName, ContentType, Data) VALUES(#ItemName, #FoundAt, #TimeIn, #ImageName, #ContentType, #Data);SELECT SCOPE_IDENTITY()";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("#ItemName", ItemName);
cmd.Parameters.AddWithValue("#FoundAt", Place);
cmd.Parameters.AddWithValue("#TimeIn", DateTime.Now);
cmd.Parameters.AddWithValue("#ImageName", imageName);
cmd.Parameters.AddWithValue("#ContentType", "image/png");
cmd.Parameters.AddWithValue("#Data", bytes);
con.Open();
Session["CapturedImageId"] = cmd.ExecuteScalar();
con.Close();
}
}
}
}
}
}
private static byte[] ConvertHexToBytes(string hex)
{
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
[WebMethod(EnableSession = true)]
public static string GetCapturedImage()
{
string url = string.Empty;
int imageId = Convert.ToInt32(HttpContext.Current.Session["CapturedImageId"]);
string VisitorManagementConnectionString = ConfigurationManager.ConnectionStrings["VisitorManagementConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(VisitorManagementConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT Data FROM LostFound WHERE Id = #Id";
cmd.Parameters.AddWithValue("#Id", imageId);
cmd.Connection = con;
con.Open();
byte[] bytes = (byte[])cmd.ExecuteScalar();
url = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
con.Close();
}
}
HttpContext.Current.Session["CapturedImageId"] = null;
return url;
}
protected void btnCapture_Click(object sender, EventArgs e)
{
}
}
The values form the textbox never inserted into the database. only
datetime.now, imageName, contentType and data can be inserted.
should the insert textbox query at btncapture?
Can someone guide me where am I going wrong?
This code should at least be in a button click.
By the time the page_load event is called in the asp.net page event life cycle the TextBoxes will have been cleared.
You're only submitting to DB if it's not a postback.
if (!this.IsPostBack)
Since you're only running this in Page_Load, the textfields will probably not have any user inputs, and is therefore blank. Either you can do it on PostBack.
if (this.IsPostBack)
{
// Do stuff
}
Or, even better, do as Jeremy Thompson suggested and assign an event handler when the user clicks a button. Doing this kind of logic in Page_Load often come back and haunt you later. What happens when some other developer adds an UpdatePanel, or another postback event? Then this code will run at every postback. It will not scale very good. It seems as you already got an event handler for this - btnCapture_Click, I suggest that you use it.
Example:
In your HTML:
<asp:Button ID="Button1" runat="server" onclick="btnCapture_Click" Text="Button" />
And in your CS:
protected void btnCapture_Click(object sender, EventArgs e)
{
if (Request.InputStream.Length > 0)
{
using (StreamReader reader = new StreamReader(Request.InputStream))
{
string hexString = Server.UrlEncode(reader.ReadToEnd());
string imageName = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
string imagePath = string.Format("~/losefound/{0}.png", imageName);
string ItemName = txtItemName.Text;
string Place = txtPlace.Text;
byte[] bytes = ConvertHexToBytes(hexString);
File.WriteAllBytes(Server.MapPath(imagePath), bytes);
string VisitorManagementConnectionString = ConfigurationManager.ConnectionStrings["VisitorManagementConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(VisitorManagementConnectionString))
{
string query = "INSERT INTO LostFound (ItemName, FoundAt, TimeIn, ImageName, ContentType, Data) VALUES(#ItemName, #FoundAt, #TimeIn, #ImageName, #ContentType, #Data);SELECT SCOPE_IDENTITY()";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("#ItemName", ItemName);
cmd.Parameters.AddWithValue("#FoundAt", Place);
cmd.Parameters.AddWithValue("#TimeIn", DateTime.Now);
cmd.Parameters.AddWithValue("#ImageName", imageName);
cmd.Parameters.AddWithValue("#ContentType", "image/png");
cmd.Parameters.AddWithValue("#Data", bytes);
con.Open();
Session["CapturedImageId"] = cmd.ExecuteScalar();
con.Close();
}
}
}
}
}
If you're having trouble binding the button you can take a look at this question.
First, check if you have AutoEventWireup="true" in the declaration of your aspx.
You can also try to manually assigning the delegate.
btnCapture += new EventHandler(btnCapture_Click);

Save an image for each contact in a datagrid control using wcf service?

In a C# silverlight application I've got a datagrid control that gets contact details from an sql database table. I can add new details to the datagrid by typing in the textboxes and clicking the add button. there is an upload button to upload an image in the Image control and works fine. but I can't seem to save an image for each contact in the table and veiw it along with the other information using wcf service.
here is what I've wrote in my upload image button:
private void uploadbtn_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "JPEG files|*.jpg";
//openFileDialog.Filter = "Images (*.jpg, *.png, *.bmp)|*.jpg;*.png;*.bmp";
if (openFileDialog.ShowDialog() == true)
{
Stream stream = (Stream)openFileDialog.File.OpenRead();
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);
MyImage.Source = bi;
string fileName = openFileDialog.File.Name;
}
}
in my add contact button I have :
ServiceReference1.Contact contact = new ServiceReference1.Contact();
ServiceReference1.Service1Client connection = new ServiceReference1.Service1Client();
connection.InsertContactCompleted += new EventHandler<ServiceReference1.InsertContactCompletedEventArgs>(connection_InsertContactCompleted);
contact.ConName = txtname.Text;
contact.ConNumber = txtnumber.Text;
contact.ConDescription = txtdescription.Text;
and in the service :
[OperationContract]
public int InsertContact(Contact cnt)
{
using (SqlConnection con = new SqlConnection(connection))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = " insert into Contact(ConName, ConNumber,ConDescription) values(#1,#2,#3)";
cmd.CommandTimeout = 300;
cmd.Parameters.Add("#1", System.Data.SqlDbType.VarChar, 50).Value = cnt.ConName;
cmd.Parameters.Add("#2", System.Data.SqlDbType.VarChar, 50).Value = cnt.ConNumber;
cmd.Parameters.Add("#3", System.Data.SqlDbType.VarChar, 50).Value = cnt.ConDescription;
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
return i;
}
else
{
return 0;
}
}
}
}
I don't know how to add the image to these codes.

Application for importing Excel datasheet

I Want to import a excel file and having trouble with the provider issue
Code are
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Windows.Documents;
using System.Windows.Controls;
using ADOX;
namespace Import
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string SelectedTable = string.Empty;
private void button1_Click_1(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Select file";
fdlg.InitialDirectory = #"c:\";
fdlg.FileName = txtFileName.Text;
fdlg.Filter = "Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = fdlg.FileName;
Import();
Application.DoEvents();
}
}
private void Import()
{
if (txtFileName.Text.Trim() != string.Empty)
{
try
{
string[] strTables = GetTableExcel(txtFileName.Text);
frmSelectTables objSelectTable = new frmSelectTables(strTables);
objSelectTable.ShowDialog(this);
objSelectTable.Dispose();
if ((SelectedTable != string.Empty) && (SelectedTable != null))
{
DataTable dt = GetDataTableExcel(txtFileName.Text, SelectedTable);
dataGridView1.DataSource = dt.DefaultView;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
public static DataTable GetDataTableExcel(string strFileName, string Table)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + strFileName + "; Extended Properties = \"Excel 12.0;HDR=Yes;IMEX=1\";");
conn.Open();
string strQuery = "SELECT * FROM [" + Table + "]";
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
System.Data.DataSet ds = new System.Data.DataSet();
adapter.Fill(ds);
return ds.Tables[0];
}
public static string[] GetTableExcel(string strFileName)
{
string[] strTables = new string[100];
Catalog oCatlog = new Catalog();
ADOX.Table oTable = new ADOX.Table();
ADODB.Connection oConn = new ADODB.Connection();
oConn.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + strFileName + "; Extended Properties = \"Excel 12.0;HDR=Yes;IMEX=1\";", "", "", 0);
oCatlog.ActiveConnection = oConn;
if (oCatlog.Tables.Count > 0)
{
int item = 0;
foreach (ADOX.Table tab in oCatlog.Tables)
{
if (tab.Type == "TABLE")
{
strTables[item] = tab.Name;
item++;
}
}
}
return strTables;
}
}
}
but the code gives Provider Can not be found,or not correctly installed
and improve the oledb connection version and Excel version in the code but thats not helping me to run the code.When I try to browse the excel file in the application i Got that error or exception
Is your operating system a 64 bit?
Do you a 64 bit installation of Microsoft Excel?
Have you installed the driver for 64 bit systems, which is available at:
http://www.microsoft.com/downloads/details.aspx?FamilyID=C06B8369-60DD-4B64-A44B-84B371EDE16D&displaylang=en
public void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Select file";
fdlg.InitialDirectory = #"d:\";
var txtFileName = fdlg.FileName;
fdlg.Filter = "Excel Sheet(*.xlsx)|*.xlsx|Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
txtFileName = fdlg.FileName;
Import(txtFileName);
System.Windows.Forms.Application.DoEvents();
}
}
private void Import(string txtFileName)
{
if (txtFileName != string.Empty)
{
try
{
String name = "Sheet1"; // default Sheet1
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
txtFileName +
";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
System.Data.DataTable data = new System.Data.DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}

How can I add a picture to a Database using DataBindign

I want to add a picture to a Database using DataBindign but I don't know how to do it .
this is the code i used to load the image:
byte[] imgData;
private void simpleButton5_Click_1(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
picture.ImageLocation = openFileDialog1.FileName;
imgData = File.ReadAllBytes(openFileDialog1.FileName);
}
}
catch (Exception ex)
{
// Could not load the image - probably related to Windows file system permissions.
XtraMessageBox.Show("Cannot display the image.\n You may not have permission to read the file, or " +
"it may be corrupt.\n\nReported error: " + ex.Message);
}
}
Here is the code how you can read BLOB (in Oracle) files from database. I hope it will help you a bit:
private void ReadFileFromDatabase()
{
byte[] fileData = null;
string selectSql = "SELECT FILE_DATA FROM BLOBTEST WHERE FILE_ID=1";
OracleConnection con = new OracleConnection(conString);
OracleCommand cmd = new OracleCommand(selectSql, con);
try
{
con.Open();
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
fileData = (byte[])reader["FILE_DATA"];
//do your operations with fileData here
}
}
}
finally
{
con.Close();
}
}

Categories