Datatable in VB.NET - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Datatable in VB.NET

tpadhutpadhu Posts: 43Member
Hi,

I've created In-Memory data table from VB.NET. (not SQL database table)
I could able to diaplay all the data in datgrid.

Actually my table looks like follows...
value1 value2 value3
10 20 1
21 30 2
31 40 3

Now i want to compare a some input (say x) with table value1 and 2.
If x>10 and <20,then i need to return 1.

If x is not within the first range,it has to move to the next line and do compare.

how to do this comparision? is it necessary to have a primary key?
How to choose a single row at a time and check the range?

Hope it'll be simple. but i run out of ideas.

Please give suggesions regarding this.
Thank You.

Comments

  • aamirwaziraamirwazir Posts: 108Member
    well its really simple
    try this function

    [code]

    Public Function CheckValue(ByVal DataTable As DataTable) As Boolean
    Try
    Dim RowPosition As Integer = 0
    While RowPosition <> DataTable.Rows.Count
    If X > DataTable.Rows(RowPosition)("Value1") And _
    X < DataTable.Rows(RowPosition)("Value2") Then

    Return True

    End If
    RowPosition += 1

    End While
    Return False
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End Function
    [/code]


  • tpadhutpadhu Posts: 43Member
    Hi,

    Thank You.

    Hey.. i would like to add xml file(existing one) with VB.NET pgm.
    I used "add existing item" option and added. Now my problem is i couldn't read and display Xml file.

    i got an error "An unhandled exception of type 'System.NullReferenceException' occurred in xmltest.exe

    Additional information: Object reference not set to an instance of an object.

    my code as follows..

    Dim ds As DataSet
    ds.ReadXml("Customers.xml")
    DataGrid1.SetDataBinding(ds, "Customers")

    Note: Xml file name is "Customers.xml"

    Note: If i click Customers.xml file, it's showing some data.but couldn't access via pgm.

    Sorry for asking these kind of simple questions.I'm very fresh to VB Environment.

    Thank You.




    : well its really simple
    : try this function
    :
    : [code]
    :
    : Public Function CheckValue(ByVal DataTable As DataTable) As Boolean
    : Try
    : Dim RowPosition As Integer = 0
    : While RowPosition <> DataTable.Rows.Count
    : If X > DataTable.Rows(RowPosition)("Value1") And _
    : X < DataTable.Rows(RowPosition)("Value2") Then
    :
    : Return True
    :
    : End If
    : RowPosition += 1
    :
    : End While
    : Return False
    : Catch ex As Exception
    : MsgBox(ex.Message)
    : End Try
    : End Function
    : [/code]
    :
    :
    :

Sign In or Register to comment.