• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

VB.Net - SQL Table Data 0 Showing as False in DataGrid

Good Day Experts!  Hope all is well with everyone.

I have never experienced or dealt with the dilema that I have at the moment.  

I Query my SQL table and load the results into a DataGridView via a comman/adapter.  The data in the SQL table is 0 or 1. I am grabbing all the 0's.  

In my DataGridView the 0's are showing as False.  The field in the Table is defined a bit.

How can I get it to show as a 0 in my DataGridView?

Thanks,
jimbo99999
0
Jimbo99999
Asked:
Jimbo99999
  • 6
  • 4
1 Solution
 
YZlatCommented:
format the column.

Can I see your DataGridView? and how you have formatted the columns
0
 
YZlatCommented:
There is a CellFormatting event you could use
0
 
YZlatCommented:
try something like that:

Private Sub dataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
	Dim grid As DataGridView = DirectCast(sender, DataGridView)
	If grid.Columns(e.ColumnIndex).Name = "your column name" Then
		e.Value = If(CBool(e.Value), "1", "0")
		e.FormattingApplied = True
	End If
End Sub

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jimbo99999Author Commented:
Where do I call the CellFormatting routine from?
0
 
YZlatCommented:
no need to call it, just add the following code:

 Private Sub dataGridView_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles dataGridView.CellFormatting
        Dim grid As DataGridView = DirectCast(sender, DataGridView)
        If grid.Columns(e.ColumnIndex).Name = "your column name" Then
            e.Value = If(CBool(e.Value), "1", "0")
            e.FormattingApplied = True
        End If
    End Sub

Open in new window

0
 
Jimbo99999Author Commented:
Ok, I have this implemented.  However, I am getting an extra row after my data in the GridView that just has a 0 in this column.  Do you know how I get this to stop happening?
0
 
YZlatCommented:
can you post the code you use to load data into your grid?
0
 
Jimbo99999Author Commented:
            '************************'
            'Assign connection string'
            '************************'
            SQLConnect = New System.Data.SqlClient.SqlConnection(SQLConnectConnStringProdEDI)
            '***********************************************************'
            '1)Build SqlCommand to Select EDI Bills from EDI Bills table'
            '2)Open SQL connection                                      '
            '***********************************************************'
            cmdGetEDIBills = New SqlCommand("Select [TRANSFERRED],[ITS CODE],[APPLICATION RECEIVERS CODE]," & _
                                            "SCAC, [PRO NUMBER],[BOL NUMBER],[PAYMENT METHOD]," & _
                                            "[BILLING DATE],[NET AMOUNT DUE],[DELIVERY DATE]," & _
                                            "[PICKUP DATE],[TRANSACTION CONTROL NUMBER],[GROUP CONTROL NUMBER] " & _
                                            "from [INVOICE HEADER] " & _
                                            "where [Transferred] = '0' and ([Billing Date] > GetDate() - 180) " & _
                                            "Order by [Billing Date] desc", SQLConnect)

            SQLConnect.Open()
            '*******************************************************************************'
            'DataAdapter to load data into DataTable "tblGetEDIBillsTable". The DataAdapater' 
            'manages() the flow of data between a DataSet and the Database.                 '
            '*******************************************************************************'
            adapterGetEDIBills = New SqlDataAdapter(cmdGetEDIBills)
            adapterGetEDIBills.Fill(tblGetEDIBillsTable)
            '*****************************************************'
            'Set btnGetAuthTable as dataSource to the dgrdCurrAuth'
            '*****************************************************'
            dgrdGetBills.AutoGenerateColumns = False
            dgrdGetBills.DataSource = tblGetEDIBillsTable
            '***************************************************************************************'
            'In order to center the column headings, a new DataGridViewCellStyle class needs created'
            'and assigned to the ColumHeaderDefaultCellStyle property.                              '
            '***************************************************************************************'
            Dim dgvColumnHeaderStyle As New DataGridViewCellStyle()
            dgvColumnHeaderStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            dgrdGetBills.ColumnHeadersDefaultCellStyle = dgvColumnHeaderStyle
            dgrdGetBills.Rows(0).Selected = False

Open in new window

0
 
YZlatCommented:
Did your issue get resolved?
0
 
Jimbo99999Author Commented:
I was able to rid the extra row by using:

dgrdGetBills.AllowUserToAddRows = False

So now I do not have the extra row.

Thanks for helping,
jimbo99999
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now