how to insert image from picturebox to database
-
im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..
-
im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..
-
im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..
as both errors indicate - the last parameter expects a byte array (byte[]) but your passing an Image object. Convert the image to a byte array first (maybe by saving to a memory stream? - google for best solution!) then pass that to the method instead.
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
gambarPictureBox.Image.Save(memStream, gambarPictureBox.Image.RawFormat);
byte[] imageBytes = memStream.ToArray();To load you'll have to do the reverse.
Dave
modified on Monday, June 2, 2008 6:37 AM
-
im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..