Click here to Skip to main content
15,907,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, how can I remove char from datatable. I have a SQL request, where I have normal value eg. 100 but datatable write me 100,000000 hav can I remove char ,000000 ? thank you

Here is problem: qer — imgbb.com[^]

What I have tried:

Public Shared Sub kusovnik(ByVal sender As Object, byval e As EventArgs) Handles MyBase.Load



        ' PRIPOJENI K DATABAZI
        Dim rs As New ADODB.Recordset
        Dim cnn As New ADODB.Connection
        Dim cmd As New ADODB.Command
        Dim rs2 As New ADODB.Recordset

        ' Otevreni spojeni
        cnn.ConnectionString = "driver={SQL Server};" & "server=000.000.000.000;uid=00;pwd=00000+;database=00000"

        Try
            cnn.Open()
            If cnn.State = 1 Then
                Assy_line_light.PripojenoPic.Show()
                Assy_line_light.PripojenoLab.Show()
                Assy_line_light.OdpojenoPic.Hide()
                Assy_line_light.OdpojenoLab.Hide()
                '' MsgBox("Spojení ověřeno ! ", , "Ověření spojení")
                ' Overeni zda pripojeni probehlo Ok
            Else
                MsgBox("Chyba v připojení k databázi.", , "Ověření připojení k databázi")
                Assy_line_light.PripojenoPic.Hide()
                Assy_line_light.PripojenoLab.Hide()
                Assy_line_light.OdpojenoPic.Show()
                Assy_line_light.OdpojenoLab.Show()
            End If
        Catch ex As Exception
            Assy_line_light.PripojenoPic.Hide()
            Assy_line_light.PripojenoLab.Hide()
            Assy_line_light.OdpojenoPic.Show()
            Assy_line_light.OdpojenoLab.Show()
            ''MsgBox("Chyba připojení k databázi!", , "Chyba")
        End Try


        ManipMat.barcodeMan = Assy_line_light.TextBox8.Text


        ' Cislo Dilu na zaklade Caroveho kodu 
        rs2 = cnn.Execute("SELECT VVyrobniOperaceKmenZbozi.RegCis From TabPrPostup LEFT OUTER JOIN TabPrikaz VVyrobniOperacePrikaz ON TabPrPostup.IDPrikaz=VVyrobniOperacePrikaz.ID LEFT OUTER JOIN TabKmenZbozi VVyrobniOperaceKmenZbozi ON TabPrPostup.dilec=VVyrobniOperaceKmenZbozi.ID WHERE TabPrPostup.BarCode = '" & ManipMat.barcodeMan & "'")


        'Cislo dilu


        'Zadany barcode


        'Podpurne tabulky pro propojeni s DB
        Dim custDA As OleDbDataAdapter = New OleDbDataAdapter()
        Dim custDS As DataSet = New DataSet
        Dim custTable As New DataTable

        custDS.Tables.Add(custTable.ToString)

        cmd.ActiveConnection = cnn
        'SQL request
        cmd.CommandText = "SELECT VKVazbyNizsiKmenZbozi.SkupZbo, VKVazbyNizsiKmenZbozi.RegCis, VKVazbyNizsiKmenZbozi.Nazev1, TabKvazby.mnozstvi
            FROM TabKvazby   
            LEFT JOIN TabCzmeny VKVazbyZmenaOdCZmeny ON TabKvazby.ZmenaOd=VKVazbyZmenaOdCZmeny.ID   
            LEFT JOIN TabCzmeny VKVazbyZmenaDoCZmeny ON TabKvazby.ZmenaDo=VKVazbyZmenaDoCZmeny.ID   
            LEFT JOIN TabKmenZbozi VKVazbyVyssiKmenZbozi ON VKVazbyVyssiKmenZbozi.ID=TabKvazby.vyssi   
            LEFT JOIN TabKmenZbozi VKVazbyNizsiKmenZbozi ON TabKvazby.nizsi=VKVazbyNizsiKmenZbozi.ID 
            WHERE(SELECT tabPostup.nazev FROM tabPostup WHERE TabPostup.dilec = VKVazbyVyssiKmenZbozi.IDKusovnik AND TabKvazby.Operace = TabPostup.Operace) = 'Balení' AND VKVazbyVyssiKmenZbozi.RegCis = (SELECT VVyrobniOperaceKmenZbozi.RegCis FROM TabPrPostup LEFT JOIN TabKmenZbozi VVyrobniOperaceKmenZbozi ON TabPrPostup.dilec = VVyrobniOperaceKmenZbozi.ID WHERE TabPrPostup.BarCode = '" & ManipMat.barcodeMan & "')"

        rs.Open(cmd)
        custDA.Fill(custTable, rs)

        'Nazvy polozek v tabulce
        custTable.Columns(0).ColumnName = "Skupina zboží"
        custTable.Columns(1).ColumnName = "Registrační číslo"
        custTable.Columns(2).ColumnName = "Název materiálu"
        custTable.Columns(3).ColumnName = "Počet kusů"



        'Naplneni nove tabulky ve formulari
        Assy_line_light.DataGridView1.DataSource = custTable

        'Ukonceni spojeni s DB
        rs.Close()
        cnn.Close()
        Assy_line_light.DataGridView1.Columns("Počet kusů").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight


    End Sub
Posted
Updated 17-Apr-18 21:00pm
v2
Comments
Jochen Arndt 17-Apr-18 5:17am    
What is the type of that column?
It looks like it is a floating point or decimal while 100 is an integer.
Member 13711215 18-Apr-18 0:57am    
this is floating point

Try something like this:
VB
Imports System
Imports System.Xml
Imports System.Data
				
Public Module Module1
	Public Sub Main()
        ' Get a DataTable instance from helper function.
        Dim table As DataTable = GetTable()
	Dim sql As String = "Dosage > 0" 
	Dim rows() As DataRow = table.Select(sql)
	
	For Each row As DataRow In rows
         	' Convert and write first value
		row(0) = Convert.ToInt32(row(0))
		Console.WriteLine(row(0))
        Next
    End Sub

    ''' <summary>
    ''' Helper function that creates new DataTable.
    ''' </summary>
    Function GetTable() As DataTable
        ' Create new DataTable instance.
        Dim table As New DataTable

        ' Create four typed columns in the DataTable.
	table.Columns.Add("Dosage", GetType(Decimal))
        table.Columns.Add("Drug", GetType(String))
        table.Columns.Add("Patient", GetType(String))
        table.Columns.Add("Date", GetType(DateTime))

        ' Add five rows with those columns filled in the DataTable.
        table.Rows.Add(25, "Indocin", "David", DateTime.Now)
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
        table.Rows.Add(21.5, "Combivent", "Janet", DateTime.Now)
        table.Rows.Add(100.0000001, "Dilantin", "Melanie", DateTime.Now)
        Return table
    End Function
	
End Module

You can also see this in action here: C# Online Compiler | .NET Fiddle[^]
 
Share this answer
 
v3
Comments
Member 13711215 17-Apr-18 6:54am    
Hi, I do in VB.NET can you help me with implementation to my code?
Member 13711215 18-Apr-18 0:58am    
Hi, not function.
You have to perform the formatting when showing the values in your DataGridView. You can set a general format:
VB
DataGridView1.Columns("Počet kusů").DefaultCellStyle.Format = "F0"
See How to: Format Data in the Windows Forms DataGridView Control | Microsoft Docs[^]. But that will format all cells in the same manner (not show any digits after the decimal point with "F0").

If you need different formats for different values, you have to create an event handler. See How to: Customize Data Formatting in the Windows Forms DataGridView Control | Microsoft Docs[^]. The example code is for C# but it is similar for all other .Net languages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900