473,666 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

after updating image from data grid view getting black color instead of images

7 New Member
I have a data grid view like this:



i am loading data grid view like this:
Expand|Select|Wrap|Line Numbers
  1. Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
  2.         adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage from CompanyMaster_tbl c join  DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)
  3.  
  4.         dt1 = New DataTable
  5.         bSource = New BindingSource
  6.         adapter.Fill(dt1) 'Filling dt with the information from the DB
  7.         bSource.DataSource = dt1
  8.         gv.DataSource = bSource
  9.         gv.Columns("cid").Visible = False
  10.         gv.Columns("dtId").Visible = False
in update button i wrote code like this:
Expand|Select|Wrap|Line Numbers
  1. adapter = New SqlDataAdapter()
  2.       Dim cid As Integer
  3.         Dim dtid As Integer
  4.         Dim cmpname As String
  5.         Dim dtname As String
  6.         Dim dtPhone As String
  7.         Dim dtEmail As String
  8.         Dim dtimage As Image
  9.  
  10.  
  11.         For i As Integer = 0 To gv.RowCount - 2
  12.            Dim rv = DirectCast(gv.Rows(i).DataBoundItem, DataRowView)
  13.             cid = rv.Row.Field(Of Integer)("Cid")
  14.  
  15.             dtid = rv.Row.Field(Of Integer)("dtId")
  16.             cmpname = rv.Row.Field(Of String)("CompanyName")
  17.             dtname = rv.Row.Field(Of String)("Department")
  18.             dtPhone = rv.Row.Field(Of String)("Phone")
  19.             dtEmail = rv.Row.Field(Of String)("Email")
  20.  
  21.             Using ms As New MemoryStream(rv.Row.Field(Of Byte())("empimage"))
  22.                 dtimage = New Bitmap(ms)
  23.             End Using
  24.  
  25.             adapter.UpdateCommand = New SqlCommand("UPDATE CompanyMaster_tbl SET CompanyName = @CompanyName", con.connect)
  26.             'this code for updating image also..
  27.             adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = @dtName,dtPhone = @dtPhone,dtEmail = @dtEmail,empimage=@dtimage  where dtId=@dtid", con.connect)
  28.             adapter.UpdateCommand.Parameters.AddWithValue("@Cid", cid)
  29.             adapter.UpdateCommand.Parameters.AddWithValue("@CompanyName", cmpname)
  30.             adapter.UpdateCommand.Parameters.AddWithValue("@dtId", dtid)
  31.             adapter.UpdateCommand.Parameters.AddWithValue("@dtName", dtname)
  32.             adapter.UpdateCommand.Parameters.AddWithValue("@dtPhone", dtPhone)
  33.             adapter.UpdateCommand.Parameters.AddWithValue("@dtEmail", dtEmail)
  34.  
  35.             Dim md As New MemoryStream()
  36.             dtimage.Save(md, System.Drawing.Imaging.ImageFormat.Gif)
  37.          ' read to end
  38.             Dim bmpBytes As Byte() = md.GetBuffer()
  39.  
  40.             ' Dim image As Byte() = System.IO.File.ReadAllBytes()
  41.             adapter.UpdateCommand.Parameters.AddWithValue("@dtimage", bmpBytes)
  42.             'adapter.UpdateCommand.Parameters.AddWithValue("@dtimage", dtimage)
  43.             adapter.UpdateCommand.ExecuteNonQuery()
after updating my first 4 column of data grid view coming proper,,but image coming something like back color,,like this:



what is wrong with my code?? any help is very appreciable?
Attached Images
File Type: jpg vsave.jpg (32.4 KB, 159 views)
File Type: jpg Black c.jpg (25.0 KB, 250 views)
Jan 26 '14 #1
0 1276

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4266
by: Joe Griffith | last post by:
I'm using a Win Forms Data Grid View control in unbound mode. When I add columns using the wizard the first item is the column name. Everything works fine. However, if you return to the columns collection and look at the poperties of an individual column the name property is not in the list. Is there a way to change (or even find) the name of a column in a data grid view other than looking at it in the *.Designer.vb file?
0
4159
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i "inizialize" the Data Grid View (add a data sorce, filled with notthing at staratup, and hide some columns) when i put a code in the txtCLCOD textbox start a searsh. If i foud something i popolate the Data grid view on the second page. Now the magic if i...
2
2785
by: Dilanka | last post by:
I want to double click on the particular data item in data grid view and get that those values to another form can somebody tell me how can i do this? i'm using visual studio .net 2005 and the language is c++
0
1753
by: nanaalwi | last post by:
hi there, im doing a project right now to download a data from EEPROM of a camcorder. i used a 'data grid view' to display all the data downloaded from the camcorder. however, i have to save the data displayed in the 'data grid view' to a text file (.txt). can anyone help me on this? really appreciate your help. anyway, im using vb.net. thanx in advance!!
1
1866
by: dineshsanduke | last post by:
hi i m new user i created programatic data grid. i want numeric cell validation in data grid view
2
3211
by: jakeesgirl | last post by:
I'm creating a C# program in Visual Studio. When I query the sql database, the results are put into a data grid view. However, the column widths are always too small when displayed. I have text that is not shown because the column width is not large enough. Is there a way I can fix that in the data grid view? I see a column height property but not a column width.
0
2736
by: cadab | last post by:
I have a data grid view, i have specified several columns through the designer that i would like to show on the grid, i have mapped them to the datasource, this works fine, the problem is, my data source contains lots of columns and some of these i do not want to show on the grid. Is there a property/option where i can just get my specified columns to show, without resorting to removing each column programticly. Thanks, James Coverdale
1
2273
by: mcupito | last post by:
I am trying to populate a data grid view based off of two text boxes, Start date and End date. I am not sure how to work with DataGridViews or DataSets. So if textbox1.text = x/x/2013 and textbox2.text = y/y/2014, then clicking a button will filter the records and display only those records with corresponding date values in the data grid view. The biggest part I am struggling with is getting the records via search button. Here's what I...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.