Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGridComboBoxColumn does not exit Pin
zaboboa21-Jul-05 7:44
zaboboa21-Jul-05 7:44 
GeneralRe: DataGridComboBoxColumn does not exit Pin
Luis Alonso Ramos21-Jul-05 7:47
Luis Alonso Ramos21-Jul-05 7:47 
GeneralProbability /statistical library Pin
machocr21-Jul-05 6:24
machocr21-Jul-05 6:24 
GeneralRe: Probability /statistical library Pin
Kevin McFarlane21-Jul-05 7:51
Kevin McFarlane21-Jul-05 7:51 
GeneralRe: Probability /statistical library Pin
machocr21-Jul-05 11:55
machocr21-Jul-05 11:55 
QuestionHow to get the currently focused mail in outlook using c#? Pin
Inbam21-Jul-05 6:16
Inbam21-Jul-05 6:16 
Generalcreate virtual ftp folder using shell extension under desktop(like My Network Places) Pin
Asif Rehman21-Jul-05 5:09
Asif Rehman21-Jul-05 5:09 
GeneralBlobs are driving me insane!!!!! Pin
kornstyle21-Jul-05 4:59
kornstyle21-Jul-05 4:59 
What I want to do is choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table in the northwind database. I am not sure what to do, I think that the problem is in my SQL statement.

What I want to do is pick a bitmap and save it to a mdb database. I am using the northwind database.


Here is my code. I have been reading on this and have been able to copy a bitmap from the "Photo" field in the "Employees" table in the northwind database, to a field in the same table that I made named Photo2.



<br />
 private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
   this.oleDbDataAdapter1.Fill(ds1, "Employees");<br />
   IDTxtBx.DataBindings.Add("Text", ds1, "Employees.EmployeeID");<br />
   firstNameTxtBx.DataBindings.Add("Text", ds1, "Employees.FirstName");<br />
			<br />
   bm = BindingContext[ds1, "Employees"];<br />
   bm.PositionChanged += new EventHandler(bm_PositionChanged);<br />
   bm_PositionChanged(null, null);<br />
}<br />
<br />
private void bm_PositionChanged(Object sender, EventArgs e)<br />
{<br />
   image = null;<br />
   this.pictureBox1.Image = null;<br />
<br />
   string sqlText = "SELECT Photo FROM Employees WHERE EmployeeID=" +<br />
   IDTxtBx.Text;<br />
<br />
   OleDbCommand cmd = new  OleDbCommand(sqlText, oleDbConnection1);<br />
<br />
   this.oleDbConnection1.Open();<br />
   try<br />
   {<br />
      int bufferSize = 100;<br />
      byte[] outbyte = new byte[bufferSize];<br />
      long retVal = 0;<br />
      long startIndex = 0;<br />
<br />
      OleDbDataReader dr = cmd.ExecuteReader           (CommandBehavior.SequentialAccess);<br />
      dr.Read();<br />
<br />
      if(!dr.IsDBNull(0))<br />
        {<br />
	     MemoryStream ms = new MemoryStream();<br />
					<br />
	     retVal = dr.GetBytes(0, startIndex, outbyte, 0, <br />
						bufferSize);<br />
				<br />
	     while(retVal == bufferSize)<br />
		{<br />
		    ms.Write(outbyte, 0, outbyte.Length);<br />
<br />
		    startIndex += bufferSize;<br />
						<br />
		    retVal = dr.GetBytes(0, startIndex, outbyte, 0, <br />
	     	    bufferSize);<br />
		}<br />
				<br />
	     ms.Write(outbyte, 0, (int)retVal - 1);<br />
<br />
	     image = ms.ToArray();<br />
	   }<br />
	}<br />
<br />
	catch(Exception ex)<br />
	   {<br />
		MessageBox.Show(ex.ToString());<br />
	   }<br />
<br />
	finally<br />
	   {<br />
		this.oleDbConnection1.Close();<br />
	   }<br />
<br />
	   if(image != null)<br />
	        {<br />
		   MemoryStream ms = new MemoryStream(image);<br />
	   try<br />
		{<br />
					<br />
		}<br />
<br />
	   catch(Exception ex)<br />
		{<br />
		   MessageBox.Show(ex.ToString());<br />
		}<br />
					ms.Close();<br />
			}<br />
		}      <br />
<br />
string sqlWrite = "UPDATE "  + "Employees" + " SET Photo2 = Photo WHERE EmployeeID = " + IDTxtBx.Text;<br />
<br />
OleDbCommand cmdWrite = new OleDbCommand(sqlWrite, this.oleDbConnection1);<br />
<br />
OleDbParameter prm;<br />
if(image != null)<br />
	{<br />
	   prm = new OleDbParameter("Photo2", OleDbType.VarBinary, <br />
	   image.Length, ParameterDirection.Input, false,<br />
	   0, 0, null, DataRowVersion.Current, image);<br />
	}<br />
<br />
	else<br />
	{<br />
	   prm = new OleDbParameter("Photo2", OleDbType.VarBinary, 0,<br />
	   ParameterDirection.Input, false,<br />
	   0, 0, null, DataRowVersion.Current,<br />
	   System.DBNull.Value);<br />
	}<br />
<br />
	   cmdWrite.Parameters.Add(prm);<br />
	   this.oleDbConnection1.Open();<br />
<br />
	   cmdWrite.ExecuteNonQuery();<br />
	   this.oleDbConnection1.Close();<br />
	   bm.EndCurrentEdit();<br />
	   this.oleDbDataAdapter1.Update(ds1.Tables["Employees"]);<br />




Instead of copying field "Photo" to "Photo2" how can I choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table.
GeneralRe: Blobs are driving me insane!!!!! Pin
Judah Gabriel Himango21-Jul-05 8:11
sponsorJudah Gabriel Himango21-Jul-05 8:11 
GeneralRe: Blobs are driving me insane!!!!! Pin
Rob Graham21-Jul-05 9:19
Rob Graham21-Jul-05 9:19 
GeneralRe: Blobs are driving me insane!!!!! Pin
kornstyle21-Jul-05 9:45
kornstyle21-Jul-05 9:45 
GeneralDead Keys Pin
Loveday7821-Jul-05 4:25
Loveday7821-Jul-05 4:25 
GeneralRe: Dead Keys Pin
LongRange.Shooter21-Jul-05 4:39
LongRange.Shooter21-Jul-05 4:39 
GeneralRe: Dead Keys Pin
Loveday7821-Jul-05 5:00
Loveday7821-Jul-05 5:00 
GeneralRe: Dead Keys Pin
Daniel Turini21-Jul-05 4:58
Daniel Turini21-Jul-05 4:58 
GeneralRe: Dead Keys Pin
Loveday7821-Jul-05 5:04
Loveday7821-Jul-05 5:04 
GeneralSearching for drag and drop item in listbox Pin
PHDENG8121-Jul-05 4:23
PHDENG8121-Jul-05 4:23 
GeneralRe: Searching for drag and drop item in listbox Pin
LongRange.Shooter21-Jul-05 4:37
LongRange.Shooter21-Jul-05 4:37 
GeneralRe: Searching for drag and drop item in listbox Pin
PHDENG8121-Jul-05 5:28
PHDENG8121-Jul-05 5:28 
GeneralRe: Searching for drag and drop item in listbox Pin
PHDENG8121-Jul-05 5:38
PHDENG8121-Jul-05 5:38 
QuestionHow to verify user input during application installation? Pin
sparks_lu21-Jul-05 4:14
sparks_lu21-Jul-05 4:14 
AnswerRe: How to verify user input during application installation? Pin
Alomgir Miah21-Jul-05 6:29
Alomgir Miah21-Jul-05 6:29 
GeneralIF / WHILE questions Pin
WetRivrRat21-Jul-05 3:58
WetRivrRat21-Jul-05 3:58 
GeneralRe: IF / WHILE questions Pin
LongRange.Shooter21-Jul-05 4:28
LongRange.Shooter21-Jul-05 4:28 
GeneralRe: IF / WHILE questions Pin
WetRivrRat21-Jul-05 4:36
WetRivrRat21-Jul-05 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.