Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

varbinary in datagridview, from data set

Posted on 2009-05-10
4
Medium Priority
?
940 Views
Last Modified: 2013-11-26
I am binding a dataset to a datagridview
in it there is a varbinary field which dsplays as a picture
if the field is null not problem but if It is not null then it crashed the datagrid
I want to edit teh dataset before i bind it,
if it is NULL then i want to show ""
if it is not null i want to just show"Encrypted Password"

I am ne to dotnet so I am relatively clueless where to start
where is what I have this far

 
Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from security whereofficerid='" & ComboBox1.SelectedValue.ToString() & "'" & _
            " and pmrespersonid = '" & TextBox2.Text & "'", cn)
            Dim DS As DataSet = New DataSet
            da.Fill(DS)
 
            DataGridView1.DataSource = DS.Tables(0)
            DS.Dispose()
            cn.Close()

Open in new window

0
Comment
Question by:hainansyndrome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24353532
You can do that with this statement

iif(isdbnull(field), "", "Encrypt Password")

Now you need to write this code in an event so that this code executes for each row.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24353552
I would think that you could do some query magic, like this:


        ' Add a reference to System.Configuration to the project.
        ' Add Imports System.Configuration at the top of the code module, to use System.Configuration.ConfigurationManager.
        ' Store the connection string in an app.config file:
        '    <?xml version="1.0" encoding="utf-8" ?>
        '    <configuration>
        '      <connectionStrings>
        '       <add name="MyDatabase" connectionString="Connection string goes here" />
        '      </connectionStrings>
        '    </configuration>
 
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("MyDatabase").ConnectionString
        Dim commandText As String = String.Format("Select Field1, Field2, Case When BinaryField IS NOT NULL THEN 'Encrypted Password' ELSE '' END " & _
            "From security where officerid='{0}' " & _
                    " and pmrespersonid = '{0}' ", ComboBox1.SelectedValue.ToString(), TextBox2.Text)
        Using da As New SqlDataAdapter(commandText, connectionString)
 
            ' Create a single DataTable
            Dim dt As New DataTable()
 
            ' Fill the DataTable with the query data.
            da.Fill(dt)
 
            ' Bind the data to the grid.
            DataGridView1.DataSource = dt
        End Using
  

Open in new window

0
 

Author Comment

by:hainansyndrome
ID: 24357667
yes i had thought about editing the query problem is i want to show every field in the table and did not want to have to write each field


CodeCruiser

can you give me an example of what you man to use that
i am not sure where to place it
before i write the dataset to a databridview?
0
 

Author Closing Comment

by:hainansyndrome
ID: 31579924
works like a champ
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question