 |
|
|
 |
|
|
 |
|
 |
How to insert the image into SQL2000 server using OLEBD Connection
Public Function insertdata(ByVal conttype As String, ByVal desc As String, ByVal title As String, ByVal date1 As Date, ByVal pic As Byte()) As Integer sql = "INSERT INTO [tblContent] ([ContentType] , [Description] , [Title], [Photo], [DateCreated]) VALUES ( " sql = sql & " '" & conttype & "' ," sql = sql & " '" & desc & "' ," sql = sql & " '" & title & "' ," sql = sql & " '" & date1 & "' ," ---- sql = sql & " & pic "---(how to write syntax for pic) sql = sql & " ) " ref.selectDataSetRecord(sql) End Function
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
plz help. I m inserting Images in Databse using OLEDB. i designed a table with column names CAMPAIGN_ID,CREATION_DATE, CREATED_BY, CONTACT_COUNT, CAMPAIGN_NAME, CAMPAIGN_PHOTOGRAPH.
CAMPAIGN_PHOTOGRAPH this is BLOB field( which support 4GB size data), in which I have to insert Image.
i have write down code below.
I m geting error either ORA-03113: end of file on communication chanel for some images
or ORA-01401: inserted value too large for column if selected some other image
Plz help.its urgent.
private void btnbrowse_Click(object sender,System.EventArgs e) { try { FileDialog fldlg=new OpenFileDialog(); fldlg.Filter="All Image Files(*.Tif;*.Bmp;*.Jpg;*.Gif;*Png)|*.Tif;*.Bmp;*.Jpg;*.Gif;*.Png"; fldlg.InitialDirectory=@"C\:"; if(fldlg.ShowDialog()==DialogResult.OK) { //imagename is string variable imagename=fldlg.FileName; Bitmap newimg=new Bitmap(imagename); pctimg.SizeMode=PictureBoxSizeMode.StretchImage; pctimg.Image=(Image)newimg; //txtName is TextBox which shows path of image file txtName.Text=String.Empty; txtName.Text=imagename; } fldlg=null; } catch(Exception ee) { imagename=""; MessageBox.Show(ee.Message.ToString()); } }
//save btton to insert image in database private void btnsave_Click(object sender, System.EventArgs e) { try { if(imagename!="") { FileStream fls=new FileStream(@imagename,FileMode.Open,FileAccess.Read); byte[] blob=new byte[fls.Length]; MessageBox.Show(blob.Length.ToString()); fls.Read(blob,0,Convert.ToInt32(fls.Length)); fls.Close(); connstr=System.Configuration.ConfigurationSettings.AppSettings["Mailer"]; conn=new OleDbConnection(connstr); conn.Open();
String dt; dt=txtDate.Text;
query="insert into CAMPAIGN_DETAILS (CAMPAIGN_ID,CREATION_DATE, CREATED_BY,CONTACT_COUNT, CAMPAIGN_NAME, CAMPAIGN_PHOTOGRAPH) values(" + id + ",'" + dt + "'," + Int32.Parse(txtDesigner.Text)+ "," + id + ",'" + txtName.Text + "',?)"; cmd=new OleDbCommand(query,conn);
OleDbParameter binParameter =new OleDbParameter(); binParameter.Value=blob; binParameter.Size=fls.Length; binParameter.OleDbType=OleDbType.Binary; binParameter.ParameterName="@CAMPAIGN_PHOTOGRAPH"; cmd.Parameters.Add(binParameter);
cmd.ExecuteNonQuery();
} } catch( OleDbException ex) { MessageBox.Show(ex.Message);
} finally { cmd.Dispose(); conn.Dispose(); } }
Pawan Kumar Dubey
Rupan Gupta
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
plz help. I m inserting Images in Databse using OLEDB. i designed a table with column names CAMPAIGN_ID,CREATION_DATE, CREATED_BY, CONTACT_COUNT, CAMPAIGN_NAME, CAMPAIGN_PHOTOGRAPH.
CAMPAIGN_PHOTOGRAPH this is BLOB field( which support 4GB size data), in which I have to insert Image.
i have write down code below.
I m geting error either ORA-03113: end of file on communication chanel for some images
or ORA-01401: inserted value too large for column if selected some other image
Plz help.its urgent.
private void btnbrowse_Click(object sender,System.EventArgs e) { try { FileDialog fldlg=new OpenFileDialog(); fldlg.Filter="All Image Files(*.Tif;*.Bmp;*.Jpg;*.Gif;*Png)|*.Tif;*.Bmp;*.Jpg;*.Gif;*.Png"; fldlg.InitialDirectory=@"C\:"; if(fldlg.ShowDialog()==DialogResult.OK) { //imagename is string variable imagename=fldlg.FileName; Bitmap newimg=new Bitmap(imagename); pctimg.SizeMode=PictureBoxSizeMode.StretchImage; pctimg.Image=(Image)newimg; //txtName is TextBox which shows path of image file txtName.Text=String.Empty; txtName.Text=imagename; } fldlg=null; } catch(Exception ee) { imagename=""; MessageBox.Show(ee.Message.ToString()); } }
//save btton to insert image in database private void btnsave_Click(object sender, System.EventArgs e) { try { if(imagename!="") { FileStream fls=new FileStream(@imagename,FileMode.Open,FileAccess.Read); byte[] blob=new byte[fls.Length]; MessageBox.Show(blob.Length.ToString()); fls.Read(blob,0,Convert.ToInt32(fls.Length)); fls.Close(); connstr=System.Configuration.ConfigurationSettings.AppSettings["Mailer"]; conn=new OleDbConnection(connstr); conn.Open();
String dt; dt=txtDate.Text;
query="insert into CAMPAIGN_DETAILS (CAMPAIGN_ID,CREATION_DATE, CREATED_BY,CONTACT_COUNT, CAMPAIGN_NAME, CAMPAIGN_PHOTOGRAPH) values(" + id + ",'" + dt + "'," + Int32.Parse(txtDesigner.Text)+ "," + id + ",'" + txtName.Text + "',?)"; cmd=new OleDbCommand(query,conn);
OleDbParameter binParameter =new OleDbParameter(); binParameter.Value=blob; binParameter.Size=fls.Length; binParameter.OleDbType=OleDbType.Binary; binParameter.ParameterName="@CAMPAIGN_PHOTOGRAPH"; cmd.Parameters.Add(binParameter);
cmd.ExecuteNonQuery();
} } catch( OleDbException ex) { MessageBox.Show(ex.Message);
} finally { cmd.Dispose(); conn.Dispose(); } }
Pawan Kumar Dubey
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
i created a database called Image in database mig16 ... heres my code for save image
private void button1_Click(object sender, EventArgs e) { byte[] content = ReadBitmap2ByteArray(@"C:\fishing.bmp"); StoreBlob2DataBase(content); }
protected static byte[] ReadBitmap2ByteArray(string fileName) { using (Bitmap image = new Bitmap(fileName)) { MemoryStream stream = new MemoryStream(); image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); return stream.ToArray(); } }
protected static void StoreBlob2DataBase(byte[] content) { SqlConnection con = new SqlConnection("Server = (local) ;Database = mig16 ;User = mig16 ; Password = 123456 ;"); con.Open(); try { // insert new entry into table SqlCommand insert = new SqlCommand( "insert into Image ([stream]) values (@image)", con); SqlParameter imageParameter = insert.Parameters.Add("@image", SqlDbType.Binary); imageParameter.Value = content; imageParameter.Size = content.Length; insert.ExecuteNonQuery(); } finally { con.Close(); } }
the exception i get is when executing nonquery.. heres the exception:
System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated.
in my table i only have 1 column...and its name its stream and its type is binary,
any body have an idea of whats going on? =(
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi, i'm using the exactly the same approach to load images to db and to retrieve them again, but i have one problem that you may have solved... I need to get the image from the picturebox as an array of bytes (byte[]) and i can't seem to get it done.
If you load a jpeg to de picturebox and then use Bitmap.Save(image,format) and the format is jpeg you recompress the image, and you you save it as a bmp you get it a bigger image. So i need to get the image as a byte array from the picturebox.. Does anyone know hot to do this?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Have you tried to load your Image into a Bitmap name image and then do something like: image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); to save as jpeg or image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); to save as bitmap
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In the program, I prepare DataBase Run SQL Server Enterprise Manager and create new database, call it 'Test'. Create new table and call it Images.
CREATE TABLE Images ([stream] [image] NULL) like it SqlCommand command=con.CreateCommand(); command.CommandText = "CREATE TABLE Images (" + "stream, " + "image);";
when i run the program, it has error in "adapter.Fill(_dataSource);". how do solve it? what's missing?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
use this code:
using(SqlConnection con = new SqlConnection(connectionString)) { con.Open(); using(SqlCommand cmd = new SqlCommand("CREATE TABLE Images ([stream] [image] NULL)", con)) { cmd.ExecuteNonQuery(); } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
insert it instead of this:
SqlCommand command=con.CreateCommand(); command.CommandText = "CREATE TABLE Images (" + "stream, " + "image);"; ... adapter.Fill(...);
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I tried to use your code and I am getting an error. At line 186 in MainForm Bitmap image = new Bitmap(stream); "Invalid Parameter Used"
Please Help!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi,
This is a really good artcile .. but being loaded with latest/ bested techniques is always better.. have a look at "Microsoft.ApplicationBlocks.Data" and improve ur artcile using this application block
L.W.C. Nirosh, Software Engineer, TextCENTRIC Technology, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | 2.33/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |