Imports System.Data
Imports System.Data.OleDb
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()
datagridshow()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub datagridshow1()
ds.Tables.Add(dt)
Try
da = New OleDbDataAdapter("select *from table1", con)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
Catch ex As Exception
MsgBox(ex.ToString)
End Try
con.Close()
End Sub
Private Sub datagridshow()
ds.Tables.Add(dt)
Try
da = New OleDbDataAdapter("select *from table2", con)
da.Fill(dt)
DataGridView2.DataSource = dt.DefaultView
Catch ex As Exception
MsgBox(ex.ToString)
End Try
con.Close()
End Sub
Private Sub RefreshData()
If Not con.State = ConnectionState.Open Then
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
da.Fill(dt)
Me.DataGridView1.DataSource = dt
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
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[
^]