Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.Data
Imports System.Data.OleDb 'import the namespace you will be needing.

Public Class frmcriteria
    Dim ds As New DataSet
    Dim dt As New DataTable
    Dim con As New OleDbConnection
    Dim da As New OleDbDataAdapter
    Dim cmd As OleDbCommand
    Private Sub frmcriteria_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Munya\Documents\Visual Studio 2010\Projects\WindowsApplication1WindowsApplication1\WindowsApplication1WindowsApplication1\bin\Debug\TEST3.accdb"
            con.Open() 'open connection
            datagridshow()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Private Sub datagridshow1()

        ds.Tables.Add(dt) 'add datatable to dataset
        Try
            da = New OleDbDataAdapter("select *from table1", con) 'select table1 from access database
            da.Fill(dt)   'Fill the Data Set
            DataGridView1.DataSource = dt.DefaultView   'Set DataSource of DataGridView 
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        con.Close()
    End Sub
    Private Sub datagridshow()

        ds.Tables.Add(dt) 'add datatable to dataset
        Try
            da = New OleDbDataAdapter("select *from table2", con) 'select table1 from access database
            da.Fill(dt)   'Fill the Data Set
            DataGridView2.DataSource = dt.DefaultView   'Set DataSource of DataGridView 
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        con.Close()
    End Sub
    Private Sub RefreshData()
        If Not con.State = ConnectionState.Open Then
            'open connection
            con.Open()
        End If
        Try
            Dim da As New OleDb.OleDbDataAdapter("SELECT ID as [ID], " & _
                                                 "Alternative as [Alternative], g1, g2, g3, g4, g5, PartialCon1, A, B, C, D, E,PartialCon2,F,G,H,I,J" & _
                                                 " FROM Table1 ORDER BY ID", con)
            Dim dt As New DataTable
            'fill data to datatable
            da.Fill(dt)

            'offer data in data table into datagridview
            Me.DataGridView1.DataSource = dt

            'close connection
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message.ToString, , "DataGrid Refresh Error")

        End Try
    End Sub

    Private Sub btnPartial1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPartial1.Click


        Dim PartialCon1 As Integer
        Dim PartialCon2 As Integer
        Dim PartialCon3 As Integer
        Dim PartialCon4 As Integer
        Dim PartialCon5 As Integer
        
        Dim i As Integer

        Dim A1, B1, C1, D1, F1 As Integer
        A1 = DataGridView1.Rows(0).Cells(8).Value
        B1 = DataGridView1.Rows(0).Cells(9).Value
        C1 = DataGridView1.Rows(0).Cells(10).Value
        D1 = DataGridView1.Rows(0).Cells(11).Value
        F1 = DataGridView1.Rows(0).Cells(12).Value

        'First Row Partial Concordance1
        For i = 0 To DataGridView1.Rows.Count - 1
            PartialCon1 = DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(0).Cells(2).Value
            PartialCon2 = DataGridView1.Rows(10).Cells(3).Value - DataGridView1.Rows(0).Cells(3).Value
            PartialCon3 = DataGridView1.Rows(10).Cells(4).Value - DataGridView1.Rows(0).Cells(4).Value
            PartialCon4 = DataGridView1.Rows(10).Cells(5).Value - DataGridView1.Rows(0).Cells(5).Value
            PartialCon5 = DataGridView1.Rows(10).Cells(6).Value - DataGridView1.Rows(0).Cells(6).Value

        Next
        If PartialCon1 >= DataGridView1.Rows(13).Cells(2).Value Then A1 = 0
        If PartialCon1 < DataGridView1.Rows(12).Cells(2).Value Then A1 = 1
        If (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(13).Cells(2).Value) < DataGridView1.Rows(0).Cells(2).Value < (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(12).Cells(2).Value) Then A1 = (DataGridView1.Rows(13).Cells(2).Value - DataGridView1.Rows(10).Cells(2).Value + DataGridView1.Rows(0).Cells(2).Value) / (DataGridView1.Rows(13).Cells(2).Value - DataGridView1.Rows(12).Cells(2).Value)

        If PartialCon2 >= DataGridView1.Rows(13).Cells(3).Value Then B1 = 0
        If PartialCon2 < DataGridView1.Rows(12).Cells(3).Value Then B1 = 1
        If (DataGridView1.Rows(10).Cells(3).Value - DataGridView1.Rows(13).Cells(3).Value) < DataGridView1.Rows(0).Cells(3).Value < (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(12).Cells(3).Value) Then B1 = (DataGridView1.Rows(13).Cells(3).Value - DataGridView1.Rows(10).Cells(3).Value + DataGridView1.Rows(0).Cells(3).Value) / (DataGridView1.Rows(13).Cells(3).Value - DataGridView1.Rows(12).Cells(3).Value)

        If PartialCon3 >= DataGridView1.Rows(13).Cells(4).Value Then C1 = 0
        If PartialCon3 < DataGridView1.Rows(12).Cells(4).Value Then C1 = 1
        If (DataGridView1.Rows(10).Cells(4).Value - DataGridView1.Rows(13).Cells(4).Value) < DataGridView1.Rows(0).Cells(4).Value < (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(12).Cells(4).Value) Then C1 = (DataGridView1.Rows(13).Cells(4).Value - DataGridView1.Rows(10).Cells(4).Value + DataGridView1.Rows(0).Cells(4).Value) / (DataGridView1.Rows(13).Cells(4).Value - DataGridView1.Rows(12).Cells(4).Value)

        If PartialCon4 >= DataGridView1.Rows(13).Cells(5).Value Then D1 = 0
        If PartialCon4 < DataGridView1.Rows(12).Cells(5).Value Then D1 = 1
        If (DataGridView1.Rows(10).Cells(5).Value - DataGridView1.Rows(13).Cells(5).Value) < DataGridView1.Rows(0).Cells(5).Value < (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(12).Cells(5).Value) Then D1 = (DataGridView1.Rows(13).Cells(5).Value - DataGridView1.Rows(10).Cells(5).Value + DataGridView1.Rows(0).Cells(5).Value) / (DataGridView1.Rows(13).Cells(5).Value - DataGridView1.Rows(12).Cells(5).Value)

        If PartialCon5 >= DataGridView1.Rows(13).Cells(6).Value Then F1 = 0
        If PartialCon5 < DataGridView1.Rows(12).Cells(6).Value Then F1 = 1
        If (DataGridView1.Rows(10).Cells(6).Value - DataGridView1.Rows(13).Cells(6).Value) < DataGridView1.Rows(0).Cells(6).Value < (DataGridView1.Rows(10).Cells(2).Value - DataGridView1.Rows(12).Cells(6).Value) Then F1 = (DataGridView1.Rows(13).Cells(6).Value - DataGridView1.Rows(10).Cells(6).Value + DataGridView1.Rows(0).Cells(6).Value) / (DataGridView1.Rows(13).Cells(6).Value - DataGridView1.Rows(12).Cells(6).Value)

   


    End Sub

End Class


http://social.msdn.microsoft.com/Forums/vstudio/en-US/9172d804-c240-476f-8d4f-8810a96c6741/how-to-return-datagrid-value?forum=vbgeneral[^]
Posted
Updated 15-Feb-14 20:18pm
v2
Comments
ahmedfaruk88 16-Feb-14 17:21pm    
Your question can not be found..... Please be more precise and state your question clearly so we can all help gain from ourselves. Its a great question but re-frame it better i know you can do that. thumbs-up for you...

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