473,473 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datarows storing incorrect data

I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.

What I have written is too extensive to post but essentially trying to:

1. Assign to a datarow (dr1) the first record of the MASTER table
2. Assign to another datarow (dr2) the second record of the MASTER table
3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
4. Assign to a third datarow (dr3) the first record of the DETAIL table
5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat this
step till last record incrementing the datarow (dr3) for the DETAIL table .

What is happening is that dr3.field2 contains the value of dr1.field2! Some
how the values in the first datarow are ending up in the third datarow.

How could this be possible?

I have not set any relations between the tables as I do not believe it is
necessary

-
Brad
Sydney, Australia
Nov 21 '05 #1
9 2044
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.

What I have written is too extensive to post but essentially trying to:

1. Assign to a datarow (dr1) the first record of the MASTER table
2. Assign to another datarow (dr2) the second record of the MASTER table
3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
4. Assign to a third datarow (dr3) the first record of the DETAIL table
5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat this
step till last record incrementing the datarow (dr3) for the DETAIL table
.

What is happening is that dr3.field2 contains the value of dr1.field2!
Some
how the values in the first datarow are ending up in the third datarow.

How could this be possible?

I have not set any relations between the tables as I do not believe it is
necessary

-
Brad
Sydney, Australia

Nov 21 '05 #2
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.

What I have written is too extensive to post but essentially trying to:

1. Assign to a datarow (dr1) the first record of the MASTER table
2. Assign to another datarow (dr2) the second record of the MASTER table
3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
4. Assign to a third datarow (dr3) the first record of the DETAIL table
5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat this
step till last record incrementing the datarow (dr3) for the DETAIL table
.

What is happening is that dr3.field2 contains the value of dr1.field2!
Some
how the values in the first datarow are ending up in the third datarow.

How could this be possible?

I have not set any relations between the tables as I do not believe it is
necessary

-
Brad
Sydney, Australia

Nov 21 '05 #3
to show some code
Nov 21 '05 #4
to show some code
Nov 21 '05 #5
Cor,
Hi. Many thanks for the code snippet. You have demonstrated how to work with
datarows which my code is lacking (I use a long winded way to achieve a
similar result...Fortran heritage is showing here).

Below is the actual code. What it does:
1. Displays a form showing a job list (this reads the JOBS table)
2. User selects a job and selects a button.
3. This buttons calls the jobconsol() function and uses the JOBNO to select
the records from OPERATIONS and JOBDETL tables
4. jobconsol() then attempts to manipulate the records by:
* Finds a duplicate records in OPERATIONS based on OPERNAME field
* If a duplicate is found it needs to move to the JOBDETL table and
modify the OPERUNIID field to point to the first OPERATIONS record
* After this the duplicates in OPERATIONS will be deleted...this is
not in the code yet.

The problem with the code is highligthed by the asterixs. This IF statement
is never true because the drCurrentJobdetl("operuniid") is always set to the
OPERATIONS.UNIID value. Very weird.

Imports System.Data
Imports FirebirdSql.Data.Firebird
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Shared myConnectionString As String 'The database connection
string
Public Shared myConnection As FbConnection 'A FB Connection to the
Database
Public Shared myTxn As FbTransaction 'A FB Transaction
Public Shared selectCmd As String 'The Select SQL
statement for displaying the list in the datagrid
Public Shared mycommand As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand1 As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand2 As FbCommand 'A SQL statement to
execute against a data source
Public Shared myReader As FbDataReader 'For reading a
forward-only stream of rows

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
BindGrid()
End Sub

Sub Connect()

'Connection string
myConnectionString = "Database=c:\Program Files\Ezijobz
SME\Database\Demo\EJDB.FDB;User=SYSDBA;
Password=masterkey;Dialect=3;Server=localhost;Pool ing=False"
myConnection = New FbConnection(myConnectionString)
myConnection.Open()
myTxn = myConnection.BeginTransaction()

End Sub

Sub BindGrid()

Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS As New DataSet ' The dataset

Connect()
dataAdapter = New FbDataAdapter
selectCmd = "SELECT jobs.jobno, jobs.jobname, jobs.jobstats,
jobs.custname, operations.squences, operations.opername, operations.descript,
operations.uniid " & _
"FROM jobs INNER JOIN operations " & _
"ON jobs.jobno = operations.jobno "
' "WHERE jobs.jobstats = ""QUOTED"" OR jobs.jobstats = ""ORDERED""
OR jobs.jobstats = ""RELEASED"""
' "ORDER BY jobs.jobno"

mycommand = New FbCommand(selectCmd, myConnection, myTxn)

Try
dataAdapter.SelectCommand = mycommand
dataAdapter.Fill(DS, "JOBS") 'filldataset

dgJobList.DataSource = DS.Tables("JOBS")
dgJobList.SetDataBinding(DS, "JOBS")
dgJobList.Refresh()

'DataGrid1.DataBind()

dataAdapter.Dispose()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

Catch Exp As FbException
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()
Exit Sub
End Try

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult

Dim selectedCell As System.Windows.Forms.DataGridCell
selectedCell = dgJobList.CurrentCell

selectedJobNo = dgJobList.Item(selectedCell.RowNumber,
selectedCell.ColumnNumber)

msg = "You are about to consolidate job number " & selectedJobNo & "
WARNING: Do you want to continue? There is no undo facility!!!"
style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or
MsgBoxStyle.YesNo
title = "Confirm the Job to Consolidate" ' Define title.

' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.

JobConsol()
End
'Dim MyForm As New Form2
'MyForm.Visible = True ' NOT Form2.Visible = True ...
your object is MyForm
'MyForm.Show()
'MyForm.Label4.Text = CStr(selectedJobNo)

Else
' Perform some other action.
End If
End Sub

Function JobConsol()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Starting the JOB
CONSOL function")

Dim ConsolCmd1 As String ' The SQL command for OPERATIONS
Dim ConsolCmd2 As String ' The SQL command for JOBDETL
Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS1 As New DataSet ' The dataset
Dim DS2 As New DataSet ' The dataset

Connect() ' Call the routine

dataAdapter = New FbDataAdapter 'Set the data adapter

'Load dataset with OPERATIONS records where @JOBNO
ConsolCmd1 = "SELECT jobno, squences, opername, uniid FROM
operations WHERE jobno = @JOBNO ORDER BY jobno"
mycommand1 = New FbCommand(ConsolCmd1, myConnection, myTxn) 'Set
the SQL
mycommand1.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand1.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand1 'Set the Data Adapter
dataAdapter.Fill(DS1, "Operations") 'Fill the Dataset with
OPERATIONS records

'Load dataset with JOBDETL records where @JOBNO
ConsolCmd2 = "SELECT jobno, operuniid, jobdetno, refid FROM jobdetl
WHERE jobno = @JOBNO ORDER BY jobno"
mycommand2 = New FbCommand(ConsolCmd2, myConnection, myTxn) 'Set
the SQL
mycommand2.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand2.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand2 'Set the Data Adapter
dataAdapter.Fill(DS2, "Jobdetl") 'Fill the Dataset with JOBDETL
records

'Define the data tables
Dim tblOperations As DataTable ' Define the OPERATIONS data table
tblOperations = DS1.Tables("Operations") ' Assign the data table
Dim tblJobdetl As DataTable ' Define the JOBDETL data table
tblJobdetl = DS2.Tables("Jobdetl") ' Assign the data table

'Declare and initialise the row counters for OPERATIONS
Dim intRowNoOperationsCurrent As Integer 'Declare and set the first
row to "0"
intRowNoOperationsCurrent = 0
Dim intRowNoOperationsNext As Integer 'Declare and set the second
row to "1"
intRowNoOperationsNext = 1
'Declare and initialise the row counters for JOBDETL
Dim intRowNoJobdetlCurrent As Integer 'Declare and set the first row
to "0"
intRowNoJobdetlCurrent = 0

'Declare and determine the number of records in the datasets
Dim intRecordNoOperations As Integer 'OPERATIONS
intRecordNoOperations = tblOperations.Rows.Count
Dim intRecordNoJobdetl As Integer ' JOBDETL
intRecordNoJobdetl = tblJobdetl.Rows.Count

' Declare and initialise a record counter for
Dim intRecordNoCountOperations As Integer ' OPERATIONS
intRecordNoCountOperations = 0
Dim intRecordNoCountJobdetl As Integer ' JOBDETL
intRecordNoCountJobdetl = 0
'Testing the decleration of datarows at this point
Dim drCurrentOperations As DataRow ' Current datarow for OPERATIONS
Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
Dim drCurrentJobdetl As DataRow ' Current datarow for JOBDETL
' Loop for each CURRENT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Loop for each NEXT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Declare and initialise the OPERATIONS datarows
'Dim drCurrentOperations As DataRow ' Current datarow for
OPERATIONS
drCurrentOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsCu rrent)
'Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
drNextOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsNe xt)

' Test if first record OPERNAME is the same as second record
OPERNAME...if so start the consolidation process
If drCurrentOperations("opername") =
drNextOperations("opername") Then

' Insert the text "DELETE OPERATION" in OPERNAME of
second record
drNextOperations("opername") = "DELETE OPERATION"

Do While intRecordNoCountJobdetl <> intRecordNoJobdetl

' Declare and initialise the JOBDETL datarows
'Dim drCurrentJobdetl As DataRow ' Current datarow
for JOBDETL
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

'Test
Dim dblOperuniid As Double
dblOperuniid = drCurrentJobdetl("operuniid")
' Test id records in JOBDETL match flUniid...if so
set to first record UNIID
* If drCurrentJobdetl("operuniid") =
drNextOperations("uniid") Then
* ' Assign to OPERUNIID the value of UNIID in the
current record of the OPERATIONS dataset
* drCurrentJobdetl("operuniid") =
drCurrentOperations("uniid")
* End If

' Increment the JOBDETL record counter
intRecordNoCountJobdetl = intRecordNoCountJobdetl + 1

' Reassign the JOBDETL datarow
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

Loop

' Insert ... UPDATE operations set opername = "DELETE
OPERATION" where uniid = @uniid

End If

intRowNoOperationsNext = intRowNoOperationsNext + 1 '
Increment the OPERATIONS NEXT record

Loop
intRowNoOperationsCurrent = intRowNoOperationsCurrent + 1 '
Increment the OPERATIONS CURRENR record
intRowNoOperationsNext = intRowNoOperationsCurrent + 1 '
Reset the OPERATIONS NEXT record to 1 + Current

' ??? intRecordNoCountOperations = intRecordNoCountOperations +
1 ' Increment the OPERATIONS record counter

Loop

'The UPDATE query...still to complete
'Dim UpdateCmd As String

'UpdateCmd = "UPDATE Operations SET Operations.squences = @squences
" & _
' "WHERE Operations.uniid = @uniid"
'mycommand = New FbCommand(UpdateCmd, myConnection, myTxn)

'The parameters for the UPDATE query
'mycommand.Parameters.Add("@squences", FbDbType.Integer)
'mycommand.Parameters("@squences").Value = drNext("squences")
'mycommand.Parameters.Add("@uniid", FbDbType.Double)
'mycommand.Parameters("@uniid").Value = fldUniid
'mycommand.ExecuteNonQuery()

myTxn.Commit()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

BindGrid()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Finished the JOB
CONSOL function")

End
End Function
End Class


"Cor Ligthert" wrote:
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.

What I have written is too extensive to post but essentially trying to:

1. Assign to a datarow (dr1) the first record of the MASTER table
2. Assign to another datarow (dr2) the second record of the MASTER table
3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
4. Assign to a third datarow (dr3) the first record of the DETAIL table
5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat this
step till last record incrementing the datarow (dr3) for the DETAIL table
.

What is happening is that dr3.field2 contains the value of dr1.field2!
Some
how the values in the first datarow are ending up in the third datarow.

How could this be possible?

I have not set any relations between the tables as I do not believe it is
necessary

-
Brad
Sydney, Australia


Nov 21 '05 #6
Cor,
Hi. Many thanks for the code snippet. You have demonstrated how to work with
datarows which my code is lacking (I use a long winded way to achieve a
similar result...Fortran heritage is showing here).

Below is the actual code. What it does:
1. Displays a form showing a job list (this reads the JOBS table)
2. User selects a job and selects a button.
3. This buttons calls the jobconsol() function and uses the JOBNO to select
the records from OPERATIONS and JOBDETL tables
4. jobconsol() then attempts to manipulate the records by:
* Finds a duplicate records in OPERATIONS based on OPERNAME field
* If a duplicate is found it needs to move to the JOBDETL table and
modify the OPERUNIID field to point to the first OPERATIONS record
* After this the duplicates in OPERATIONS will be deleted...this is
not in the code yet.

The problem with the code is highligthed by the asterixs. This IF statement
is never true because the drCurrentJobdetl("operuniid") is always set to the
OPERATIONS.UNIID value. Very weird.

Imports System.Data
Imports FirebirdSql.Data.Firebird
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Shared myConnectionString As String 'The database connection
string
Public Shared myConnection As FbConnection 'A FB Connection to the
Database
Public Shared myTxn As FbTransaction 'A FB Transaction
Public Shared selectCmd As String 'The Select SQL
statement for displaying the list in the datagrid
Public Shared mycommand As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand1 As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand2 As FbCommand 'A SQL statement to
execute against a data source
Public Shared myReader As FbDataReader 'For reading a
forward-only stream of rows

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
BindGrid()
End Sub

Sub Connect()

'Connection string
myConnectionString = "Database=c:\Program Files\Ezijobz
SME\Database\Demo\EJDB.FDB;User=SYSDBA;
Password=masterkey;Dialect=3;Server=localhost;Pool ing=False"
myConnection = New FbConnection(myConnectionString)
myConnection.Open()
myTxn = myConnection.BeginTransaction()

End Sub

Sub BindGrid()

Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS As New DataSet ' The dataset

Connect()
dataAdapter = New FbDataAdapter
selectCmd = "SELECT jobs.jobno, jobs.jobname, jobs.jobstats,
jobs.custname, operations.squences, operations.opername, operations.descript,
operations.uniid " & _
"FROM jobs INNER JOIN operations " & _
"ON jobs.jobno = operations.jobno "
' "WHERE jobs.jobstats = ""QUOTED"" OR jobs.jobstats = ""ORDERED""
OR jobs.jobstats = ""RELEASED"""
' "ORDER BY jobs.jobno"

mycommand = New FbCommand(selectCmd, myConnection, myTxn)

Try
dataAdapter.SelectCommand = mycommand
dataAdapter.Fill(DS, "JOBS") 'filldataset

dgJobList.DataSource = DS.Tables("JOBS")
dgJobList.SetDataBinding(DS, "JOBS")
dgJobList.Refresh()

'DataGrid1.DataBind()

dataAdapter.Dispose()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

Catch Exp As FbException
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()
Exit Sub
End Try

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult

Dim selectedCell As System.Windows.Forms.DataGridCell
selectedCell = dgJobList.CurrentCell

selectedJobNo = dgJobList.Item(selectedCell.RowNumber,
selectedCell.ColumnNumber)

msg = "You are about to consolidate job number " & selectedJobNo & "
WARNING: Do you want to continue? There is no undo facility!!!"
style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or
MsgBoxStyle.YesNo
title = "Confirm the Job to Consolidate" ' Define title.

' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.

JobConsol()
End
'Dim MyForm As New Form2
'MyForm.Visible = True ' NOT Form2.Visible = True ...
your object is MyForm
'MyForm.Show()
'MyForm.Label4.Text = CStr(selectedJobNo)

Else
' Perform some other action.
End If
End Sub

Function JobConsol()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Starting the JOB
CONSOL function")

Dim ConsolCmd1 As String ' The SQL command for OPERATIONS
Dim ConsolCmd2 As String ' The SQL command for JOBDETL
Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS1 As New DataSet ' The dataset
Dim DS2 As New DataSet ' The dataset

Connect() ' Call the routine

dataAdapter = New FbDataAdapter 'Set the data adapter

'Load dataset with OPERATIONS records where @JOBNO
ConsolCmd1 = "SELECT jobno, squences, opername, uniid FROM
operations WHERE jobno = @JOBNO ORDER BY jobno"
mycommand1 = New FbCommand(ConsolCmd1, myConnection, myTxn) 'Set
the SQL
mycommand1.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand1.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand1 'Set the Data Adapter
dataAdapter.Fill(DS1, "Operations") 'Fill the Dataset with
OPERATIONS records

'Load dataset with JOBDETL records where @JOBNO
ConsolCmd2 = "SELECT jobno, operuniid, jobdetno, refid FROM jobdetl
WHERE jobno = @JOBNO ORDER BY jobno"
mycommand2 = New FbCommand(ConsolCmd2, myConnection, myTxn) 'Set
the SQL
mycommand2.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand2.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand2 'Set the Data Adapter
dataAdapter.Fill(DS2, "Jobdetl") 'Fill the Dataset with JOBDETL
records

'Define the data tables
Dim tblOperations As DataTable ' Define the OPERATIONS data table
tblOperations = DS1.Tables("Operations") ' Assign the data table
Dim tblJobdetl As DataTable ' Define the JOBDETL data table
tblJobdetl = DS2.Tables("Jobdetl") ' Assign the data table

'Declare and initialise the row counters for OPERATIONS
Dim intRowNoOperationsCurrent As Integer 'Declare and set the first
row to "0"
intRowNoOperationsCurrent = 0
Dim intRowNoOperationsNext As Integer 'Declare and set the second
row to "1"
intRowNoOperationsNext = 1
'Declare and initialise the row counters for JOBDETL
Dim intRowNoJobdetlCurrent As Integer 'Declare and set the first row
to "0"
intRowNoJobdetlCurrent = 0

'Declare and determine the number of records in the datasets
Dim intRecordNoOperations As Integer 'OPERATIONS
intRecordNoOperations = tblOperations.Rows.Count
Dim intRecordNoJobdetl As Integer ' JOBDETL
intRecordNoJobdetl = tblJobdetl.Rows.Count

' Declare and initialise a record counter for
Dim intRecordNoCountOperations As Integer ' OPERATIONS
intRecordNoCountOperations = 0
Dim intRecordNoCountJobdetl As Integer ' JOBDETL
intRecordNoCountJobdetl = 0
'Testing the decleration of datarows at this point
Dim drCurrentOperations As DataRow ' Current datarow for OPERATIONS
Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
Dim drCurrentJobdetl As DataRow ' Current datarow for JOBDETL
' Loop for each CURRENT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Loop for each NEXT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Declare and initialise the OPERATIONS datarows
'Dim drCurrentOperations As DataRow ' Current datarow for
OPERATIONS
drCurrentOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsCu rrent)
'Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
drNextOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsNe xt)

' Test if first record OPERNAME is the same as second record
OPERNAME...if so start the consolidation process
If drCurrentOperations("opername") =
drNextOperations("opername") Then

' Insert the text "DELETE OPERATION" in OPERNAME of
second record
drNextOperations("opername") = "DELETE OPERATION"

Do While intRecordNoCountJobdetl <> intRecordNoJobdetl

' Declare and initialise the JOBDETL datarows
'Dim drCurrentJobdetl As DataRow ' Current datarow
for JOBDETL
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

'Test
Dim dblOperuniid As Double
dblOperuniid = drCurrentJobdetl("operuniid")
' Test id records in JOBDETL match flUniid...if so
set to first record UNIID
* If drCurrentJobdetl("operuniid") =
drNextOperations("uniid") Then
* ' Assign to OPERUNIID the value of UNIID in the
current record of the OPERATIONS dataset
* drCurrentJobdetl("operuniid") =
drCurrentOperations("uniid")
* End If

' Increment the JOBDETL record counter
intRecordNoCountJobdetl = intRecordNoCountJobdetl + 1

' Reassign the JOBDETL datarow
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

Loop

' Insert ... UPDATE operations set opername = "DELETE
OPERATION" where uniid = @uniid

End If

intRowNoOperationsNext = intRowNoOperationsNext + 1 '
Increment the OPERATIONS NEXT record

Loop
intRowNoOperationsCurrent = intRowNoOperationsCurrent + 1 '
Increment the OPERATIONS CURRENR record
intRowNoOperationsNext = intRowNoOperationsCurrent + 1 '
Reset the OPERATIONS NEXT record to 1 + Current

' ??? intRecordNoCountOperations = intRecordNoCountOperations +
1 ' Increment the OPERATIONS record counter

Loop

'The UPDATE query...still to complete
'Dim UpdateCmd As String

'UpdateCmd = "UPDATE Operations SET Operations.squences = @squences
" & _
' "WHERE Operations.uniid = @uniid"
'mycommand = New FbCommand(UpdateCmd, myConnection, myTxn)

'The parameters for the UPDATE query
'mycommand.Parameters.Add("@squences", FbDbType.Integer)
'mycommand.Parameters("@squences").Value = drNext("squences")
'mycommand.Parameters.Add("@uniid", FbDbType.Double)
'mycommand.Parameters("@uniid").Value = fldUniid
'mycommand.ExecuteNonQuery()

myTxn.Commit()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

BindGrid()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Finished the JOB
CONSOL function")

End
End Function
End Class


"Cor Ligthert" wrote:
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.

What I have written is too extensive to post but essentially trying to:

1. Assign to a datarow (dr1) the first record of the MASTER table
2. Assign to another datarow (dr2) the second record of the MASTER table
3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
4. Assign to a third datarow (dr3) the first record of the DETAIL table
5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat this
step till last record incrementing the datarow (dr3) for the DETAIL table
.

What is happening is that dr3.field2 contains the value of dr1.field2!
Some
how the values in the first datarow are ending up in the third datarow.

How could this be possible?

I have not set any relations between the tables as I do not believe it is
necessary

-
Brad
Sydney, Australia


Nov 21 '05 #7
Brad,

As you said, you use in my opinion as well to much code and tries in my
opinion a classic way of coding to use with VBNet, what will in my opinion
not give the result you want to get and make it everytime more difficult.

Did you ever use the resource kit.

There are samples from master detail grids and a lot more. When I was you I
would have a look to it. It is mostly good code while on MSDN old not
complete translated VB6 or bad translated C# what you have to be able to
know before you see it.

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I myself have at this moment the problem that the samples do not open after
that I updated my system. I do not know it that is with everybody.

You can than open the samples by the way, by copying the shortcut and to
open that using copy and paste.

When you have that open problem as well, will you than tell me that?

Cor

"Brad" <Br**@discussions.microsoft.com>
Cor,
Hi. Many thanks for the code snippet. You have demonstrated how to work
with
datarows which my code is lacking (I use a long winded way to achieve a
similar result...Fortran heritage is showing here).

Below is the actual code. What it does:
1. Displays a form showing a job list (this reads the JOBS table)
2. User selects a job and selects a button.
3. This buttons calls the jobconsol() function and uses the JOBNO to
select
the records from OPERATIONS and JOBDETL tables
4. jobconsol() then attempts to manipulate the records by:
* Finds a duplicate records in OPERATIONS based on OPERNAME field
* If a duplicate is found it needs to move to the JOBDETL table and
modify the OPERUNIID field to point to the first OPERATIONS record
* After this the duplicates in OPERATIONS will be deleted...this is
not in the code yet.

The problem with the code is highligthed by the asterixs. This IF
statement
is never true because the drCurrentJobdetl("operuniid") is always set to
the
OPERATIONS.UNIID value. Very weird.

Imports System.Data
Imports FirebirdSql.Data.Firebird
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Shared myConnectionString As String 'The database
connection
string
Public Shared myConnection As FbConnection 'A FB Connection to
the
Database
Public Shared myTxn As FbTransaction 'A FB Transaction
Public Shared selectCmd As String 'The Select SQL
statement for displaying the list in the datagrid
Public Shared mycommand As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand1 As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand2 As FbCommand 'A SQL statement to
execute against a data source
Public Shared myReader As FbDataReader 'For reading a
forward-only stream of rows

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
BindGrid()
End Sub

Sub Connect()

'Connection string
myConnectionString = "Database=c:\Program Files\Ezijobz
SME\Database\Demo\EJDB.FDB;User=SYSDBA;
Password=masterkey;Dialect=3;Server=localhost;Pool ing=False"
myConnection = New FbConnection(myConnectionString)
myConnection.Open()
myTxn = myConnection.BeginTransaction()

End Sub

Sub BindGrid()

Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS As New DataSet ' The dataset

Connect()
dataAdapter = New FbDataAdapter
selectCmd = "SELECT jobs.jobno, jobs.jobname, jobs.jobstats,
jobs.custname, operations.squences, operations.opername,
operations.descript,
operations.uniid " & _
"FROM jobs INNER JOIN operations " & _
"ON jobs.jobno = operations.jobno "
' "WHERE jobs.jobstats = ""QUOTED"" OR jobs.jobstats = ""ORDERED""
OR jobs.jobstats = ""RELEASED"""
' "ORDER BY jobs.jobno"

mycommand = New FbCommand(selectCmd, myConnection, myTxn)

Try
dataAdapter.SelectCommand = mycommand
dataAdapter.Fill(DS, "JOBS") 'filldataset

dgJobList.DataSource = DS.Tables("JOBS")
dgJobList.SetDataBinding(DS, "JOBS")
dgJobList.Refresh()

'DataGrid1.DataBind()

dataAdapter.Dispose()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

Catch Exp As FbException
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()
Exit Sub
End Try

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult

Dim selectedCell As System.Windows.Forms.DataGridCell
selectedCell = dgJobList.CurrentCell

selectedJobNo = dgJobList.Item(selectedCell.RowNumber,
selectedCell.ColumnNumber)

msg = "You are about to consolidate job number " & selectedJobNo &
"
WARNING: Do you want to continue? There is no undo facility!!!"
style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or
MsgBoxStyle.YesNo
title = "Confirm the Job to Consolidate" ' Define title.

' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.

JobConsol()
End
'Dim MyForm As New Form2
'MyForm.Visible = True ' NOT Form2.Visible = True ...
your object is MyForm
'MyForm.Show()
'MyForm.Label4.Text = CStr(selectedJobNo)

Else
' Perform some other action.
End If
End Sub

Function JobConsol()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Starting the JOB
CONSOL function")

Dim ConsolCmd1 As String ' The SQL command for
OPERATIONS
Dim ConsolCmd2 As String ' The SQL command for JOBDETL
Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS1 As New DataSet ' The dataset
Dim DS2 As New DataSet ' The dataset

Connect() ' Call the routine

dataAdapter = New FbDataAdapter 'Set the data adapter

'Load dataset with OPERATIONS records where @JOBNO
ConsolCmd1 = "SELECT jobno, squences, opername, uniid FROM
operations WHERE jobno = @JOBNO ORDER BY jobno"
mycommand1 = New FbCommand(ConsolCmd1, myConnection, myTxn) 'Set
the SQL
mycommand1.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand1.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand1 'Set the Data Adapter
dataAdapter.Fill(DS1, "Operations") 'Fill the Dataset with
OPERATIONS records

'Load dataset with JOBDETL records where @JOBNO
ConsolCmd2 = "SELECT jobno, operuniid, jobdetno, refid FROM jobdetl
WHERE jobno = @JOBNO ORDER BY jobno"
mycommand2 = New FbCommand(ConsolCmd2, myConnection, myTxn) 'Set
the SQL
mycommand2.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand2.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand2 'Set the Data Adapter
dataAdapter.Fill(DS2, "Jobdetl") 'Fill the Dataset with
JOBDETL
records

'Define the data tables
Dim tblOperations As DataTable ' Define the OPERATIONS data table
tblOperations = DS1.Tables("Operations") ' Assign the data table
Dim tblJobdetl As DataTable ' Define the JOBDETL data table
tblJobdetl = DS2.Tables("Jobdetl") ' Assign the data table

'Declare and initialise the row counters for OPERATIONS
Dim intRowNoOperationsCurrent As Integer 'Declare and set the first
row to "0"
intRowNoOperationsCurrent = 0
Dim intRowNoOperationsNext As Integer 'Declare and set the second
row to "1"
intRowNoOperationsNext = 1
'Declare and initialise the row counters for JOBDETL
Dim intRowNoJobdetlCurrent As Integer 'Declare and set the first
row
to "0"
intRowNoJobdetlCurrent = 0

'Declare and determine the number of records in the datasets
Dim intRecordNoOperations As Integer 'OPERATIONS
intRecordNoOperations = tblOperations.Rows.Count
Dim intRecordNoJobdetl As Integer ' JOBDETL
intRecordNoJobdetl = tblJobdetl.Rows.Count

' Declare and initialise a record counter for
Dim intRecordNoCountOperations As Integer ' OPERATIONS
intRecordNoCountOperations = 0
Dim intRecordNoCountJobdetl As Integer ' JOBDETL
intRecordNoCountJobdetl = 0
'Testing the decleration of datarows at this point
Dim drCurrentOperations As DataRow ' Current datarow for OPERATIONS
Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
Dim drCurrentJobdetl As DataRow ' Current datarow for JOBDETL
' Loop for each CURRENT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Loop for each NEXT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Declare and initialise the OPERATIONS datarows
'Dim drCurrentOperations As DataRow ' Current datarow for
OPERATIONS
drCurrentOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsCu rrent)
'Dim drNextOperations As DataRow ' Next datarow for
OPERATIONS
drNextOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsNe xt)

' Test if first record OPERNAME is the same as second
record
OPERNAME...if so start the consolidation process
If drCurrentOperations("opername") =
drNextOperations("opername") Then

' Insert the text "DELETE OPERATION" in OPERNAME of
second record
drNextOperations("opername") = "DELETE OPERATION"

Do While intRecordNoCountJobdetl <> intRecordNoJobdetl

' Declare and initialise the JOBDETL datarows
'Dim drCurrentJobdetl As DataRow ' Current datarow
for JOBDETL
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

'Test
Dim dblOperuniid As Double
dblOperuniid = drCurrentJobdetl("operuniid")
' Test id records in JOBDETL match flUniid...if so
set to first record UNIID
* If drCurrentJobdetl("operuniid") =
drNextOperations("uniid") Then
* ' Assign to OPERUNIID the value of UNIID in
the
current record of the OPERATIONS dataset
* drCurrentJobdetl("operuniid") =
drCurrentOperations("uniid")
* End If

' Increment the JOBDETL record counter
intRecordNoCountJobdetl = intRecordNoCountJobdetl +
1

' Reassign the JOBDETL datarow
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

Loop

' Insert ... UPDATE operations set opername = "DELETE
OPERATION" where uniid = @uniid

End If

intRowNoOperationsNext = intRowNoOperationsNext + 1 '
Increment the OPERATIONS NEXT record

Loop
intRowNoOperationsCurrent = intRowNoOperationsCurrent + 1 '
Increment the OPERATIONS CURRENR record
intRowNoOperationsNext = intRowNoOperationsCurrent + 1 '
Reset the OPERATIONS NEXT record to 1 + Current

' ??? intRecordNoCountOperations = intRecordNoCountOperations +
1 ' Increment the OPERATIONS record counter

Loop

'The UPDATE query...still to complete
'Dim UpdateCmd As String

'UpdateCmd = "UPDATE Operations SET Operations.squences = @squences
" & _
' "WHERE Operations.uniid = @uniid"
'mycommand = New FbCommand(UpdateCmd, myConnection, myTxn)

'The parameters for the UPDATE query
'mycommand.Parameters.Add("@squences", FbDbType.Integer)
'mycommand.Parameters("@squences").Value = drNext("squences")
'mycommand.Parameters.Add("@uniid", FbDbType.Double)
'mycommand.Parameters("@uniid").Value = fldUniid
'mycommand.ExecuteNonQuery()

myTxn.Commit()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

BindGrid()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Finished the JOB
CONSOL function")

End
End Function
End Class


"Cor Ligthert" wrote:
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
>I have written some code to manipulate data/records in a MASTER (order
> header) and DETAIL (order details) tables.
>
> What I have written is too extensive to post but essentially trying to:
>
> 1. Assign to a datarow (dr1) the first record of the MASTER table
> 2. Assign to another datarow (dr2) the second record of the MASTER
> table
> 3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
> 4. Assign to a third datarow (dr3) the first record of the DETAIL table
> 5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat
> this
> step till last record incrementing the datarow (dr3) for the DETAIL
> table
> .
>
> What is happening is that dr3.field2 contains the value of dr1.field2!
> Some
> how the values in the first datarow are ending up in the third datarow.
>
> How could this be possible?
>
> I have not set any relations between the tables as I do not believe it
> is
> necessary
>
> -
> Brad
> Sydney, Australia


Nov 21 '05 #8
Brad,

As you said, you use in my opinion as well to much code and tries in my
opinion a classic way of coding to use with VBNet, what will in my opinion
not give the result you want to get and make it everytime more difficult.

Did you ever use the resource kit.

There are samples from master detail grids and a lot more. When I was you I
would have a look to it. It is mostly good code while on MSDN old not
complete translated VB6 or bad translated C# what you have to be able to
know before you see it.

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I myself have at this moment the problem that the samples do not open after
that I updated my system. I do not know it that is with everybody.

You can than open the samples by the way, by copying the shortcut and to
open that using copy and paste.

When you have that open problem as well, will you than tell me that?

Cor

"Brad" <Br**@discussions.microsoft.com>
Cor,
Hi. Many thanks for the code snippet. You have demonstrated how to work
with
datarows which my code is lacking (I use a long winded way to achieve a
similar result...Fortran heritage is showing here).

Below is the actual code. What it does:
1. Displays a form showing a job list (this reads the JOBS table)
2. User selects a job and selects a button.
3. This buttons calls the jobconsol() function and uses the JOBNO to
select
the records from OPERATIONS and JOBDETL tables
4. jobconsol() then attempts to manipulate the records by:
* Finds a duplicate records in OPERATIONS based on OPERNAME field
* If a duplicate is found it needs to move to the JOBDETL table and
modify the OPERUNIID field to point to the first OPERATIONS record
* After this the duplicates in OPERATIONS will be deleted...this is
not in the code yet.

The problem with the code is highligthed by the asterixs. This IF
statement
is never true because the drCurrentJobdetl("operuniid") is always set to
the
OPERATIONS.UNIID value. Very weird.

Imports System.Data
Imports FirebirdSql.Data.Firebird
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Shared myConnectionString As String 'The database
connection
string
Public Shared myConnection As FbConnection 'A FB Connection to
the
Database
Public Shared myTxn As FbTransaction 'A FB Transaction
Public Shared selectCmd As String 'The Select SQL
statement for displaying the list in the datagrid
Public Shared mycommand As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand1 As FbCommand 'A SQL statement to
execute against a data source
Public Shared mycommand2 As FbCommand 'A SQL statement to
execute against a data source
Public Shared myReader As FbDataReader 'For reading a
forward-only stream of rows

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
BindGrid()
End Sub

Sub Connect()

'Connection string
myConnectionString = "Database=c:\Program Files\Ezijobz
SME\Database\Demo\EJDB.FDB;User=SYSDBA;
Password=masterkey;Dialect=3;Server=localhost;Pool ing=False"
myConnection = New FbConnection(myConnectionString)
myConnection.Open()
myTxn = myConnection.BeginTransaction()

End Sub

Sub BindGrid()

Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS As New DataSet ' The dataset

Connect()
dataAdapter = New FbDataAdapter
selectCmd = "SELECT jobs.jobno, jobs.jobname, jobs.jobstats,
jobs.custname, operations.squences, operations.opername,
operations.descript,
operations.uniid " & _
"FROM jobs INNER JOIN operations " & _
"ON jobs.jobno = operations.jobno "
' "WHERE jobs.jobstats = ""QUOTED"" OR jobs.jobstats = ""ORDERED""
OR jobs.jobstats = ""RELEASED"""
' "ORDER BY jobs.jobno"

mycommand = New FbCommand(selectCmd, myConnection, myTxn)

Try
dataAdapter.SelectCommand = mycommand
dataAdapter.Fill(DS, "JOBS") 'filldataset

dgJobList.DataSource = DS.Tables("JOBS")
dgJobList.SetDataBinding(DS, "JOBS")
dgJobList.Refresh()

'DataGrid1.DataBind()

dataAdapter.Dispose()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

Catch Exp As FbException
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()
Exit Sub
End Try

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult

Dim selectedCell As System.Windows.Forms.DataGridCell
selectedCell = dgJobList.CurrentCell

selectedJobNo = dgJobList.Item(selectedCell.RowNumber,
selectedCell.ColumnNumber)

msg = "You are about to consolidate job number " & selectedJobNo &
"
WARNING: Do you want to continue? There is no undo facility!!!"
style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or
MsgBoxStyle.YesNo
title = "Confirm the Job to Consolidate" ' Define title.

' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.

JobConsol()
End
'Dim MyForm As New Form2
'MyForm.Visible = True ' NOT Form2.Visible = True ...
your object is MyForm
'MyForm.Show()
'MyForm.Label4.Text = CStr(selectedJobNo)

Else
' Perform some other action.
End If
End Sub

Function JobConsol()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Starting the JOB
CONSOL function")

Dim ConsolCmd1 As String ' The SQL command for
OPERATIONS
Dim ConsolCmd2 As String ' The SQL command for JOBDETL
Dim dataAdapter As FbDataAdapter ' The FB Data Adapter
Dim DS1 As New DataSet ' The dataset
Dim DS2 As New DataSet ' The dataset

Connect() ' Call the routine

dataAdapter = New FbDataAdapter 'Set the data adapter

'Load dataset with OPERATIONS records where @JOBNO
ConsolCmd1 = "SELECT jobno, squences, opername, uniid FROM
operations WHERE jobno = @JOBNO ORDER BY jobno"
mycommand1 = New FbCommand(ConsolCmd1, myConnection, myTxn) 'Set
the SQL
mycommand1.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand1.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand1 'Set the Data Adapter
dataAdapter.Fill(DS1, "Operations") 'Fill the Dataset with
OPERATIONS records

'Load dataset with JOBDETL records where @JOBNO
ConsolCmd2 = "SELECT jobno, operuniid, jobdetno, refid FROM jobdetl
WHERE jobno = @JOBNO ORDER BY jobno"
mycommand2 = New FbCommand(ConsolCmd2, myConnection, myTxn) 'Set
the SQL
mycommand2.Parameters.Add("@JOBNO", FbDbType.Char)
mycommand2.Parameters("@JOBNO").Value = selectedJobNo
dataAdapter.SelectCommand = mycommand2 'Set the Data Adapter
dataAdapter.Fill(DS2, "Jobdetl") 'Fill the Dataset with
JOBDETL
records

'Define the data tables
Dim tblOperations As DataTable ' Define the OPERATIONS data table
tblOperations = DS1.Tables("Operations") ' Assign the data table
Dim tblJobdetl As DataTable ' Define the JOBDETL data table
tblJobdetl = DS2.Tables("Jobdetl") ' Assign the data table

'Declare and initialise the row counters for OPERATIONS
Dim intRowNoOperationsCurrent As Integer 'Declare and set the first
row to "0"
intRowNoOperationsCurrent = 0
Dim intRowNoOperationsNext As Integer 'Declare and set the second
row to "1"
intRowNoOperationsNext = 1
'Declare and initialise the row counters for JOBDETL
Dim intRowNoJobdetlCurrent As Integer 'Declare and set the first
row
to "0"
intRowNoJobdetlCurrent = 0

'Declare and determine the number of records in the datasets
Dim intRecordNoOperations As Integer 'OPERATIONS
intRecordNoOperations = tblOperations.Rows.Count
Dim intRecordNoJobdetl As Integer ' JOBDETL
intRecordNoJobdetl = tblJobdetl.Rows.Count

' Declare and initialise a record counter for
Dim intRecordNoCountOperations As Integer ' OPERATIONS
intRecordNoCountOperations = 0
Dim intRecordNoCountJobdetl As Integer ' JOBDETL
intRecordNoCountJobdetl = 0
'Testing the decleration of datarows at this point
Dim drCurrentOperations As DataRow ' Current datarow for OPERATIONS
Dim drNextOperations As DataRow ' Next datarow for OPERATIONS
Dim drCurrentJobdetl As DataRow ' Current datarow for JOBDETL
' Loop for each CURRENT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Loop for each NEXT OPERATION record
Do While intRowNoOperationsNext <> intRecordNoOperations

' Declare and initialise the OPERATIONS datarows
'Dim drCurrentOperations As DataRow ' Current datarow for
OPERATIONS
drCurrentOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsCu rrent)
'Dim drNextOperations As DataRow ' Next datarow for
OPERATIONS
drNextOperations =
DS1.Tables("Operations").Rows(intRowNoOperationsNe xt)

' Test if first record OPERNAME is the same as second
record
OPERNAME...if so start the consolidation process
If drCurrentOperations("opername") =
drNextOperations("opername") Then

' Insert the text "DELETE OPERATION" in OPERNAME of
second record
drNextOperations("opername") = "DELETE OPERATION"

Do While intRecordNoCountJobdetl <> intRecordNoJobdetl

' Declare and initialise the JOBDETL datarows
'Dim drCurrentJobdetl As DataRow ' Current datarow
for JOBDETL
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

'Test
Dim dblOperuniid As Double
dblOperuniid = drCurrentJobdetl("operuniid")
' Test id records in JOBDETL match flUniid...if so
set to first record UNIID
* If drCurrentJobdetl("operuniid") =
drNextOperations("uniid") Then
* ' Assign to OPERUNIID the value of UNIID in
the
current record of the OPERATIONS dataset
* drCurrentJobdetl("operuniid") =
drCurrentOperations("uniid")
* End If

' Increment the JOBDETL record counter
intRecordNoCountJobdetl = intRecordNoCountJobdetl +
1

' Reassign the JOBDETL datarow
drCurrentJobdetl =
DS2.Tables("Jobdetl").Rows(intRowNoJobdetlCurrent)

Loop

' Insert ... UPDATE operations set opername = "DELETE
OPERATION" where uniid = @uniid

End If

intRowNoOperationsNext = intRowNoOperationsNext + 1 '
Increment the OPERATIONS NEXT record

Loop
intRowNoOperationsCurrent = intRowNoOperationsCurrent + 1 '
Increment the OPERATIONS CURRENR record
intRowNoOperationsNext = intRowNoOperationsCurrent + 1 '
Reset the OPERATIONS NEXT record to 1 + Current

' ??? intRecordNoCountOperations = intRecordNoCountOperations +
1 ' Increment the OPERATIONS record counter

Loop

'The UPDATE query...still to complete
'Dim UpdateCmd As String

'UpdateCmd = "UPDATE Operations SET Operations.squences = @squences
" & _
' "WHERE Operations.uniid = @uniid"
'mycommand = New FbCommand(UpdateCmd, myConnection, myTxn)

'The parameters for the UPDATE query
'mycommand.Parameters.Add("@squences", FbDbType.Integer)
'mycommand.Parameters("@squences").Value = drNext("squences")
'mycommand.Parameters.Add("@uniid", FbDbType.Double)
'mycommand.Parameters("@uniid").Value = fldUniid
'mycommand.ExecuteNonQuery()

myTxn.Commit()
myTxn.Dispose()
mycommand.Dispose()
myConnection.Close()

BindGrid()

MsgBox(selectedJobNo, MsgBoxStyle.DefaultButton2, "Finished the JOB
CONSOL function")

End
End Function
End Class


"Cor Ligthert" wrote:
Brad,

I think you need some code, when I write in what you tells here in code I
get something as
\\\
If ds.tables("master").rows(0)(0) = ds.tables("master").rows(1)(0) then
dim lr as integer = 0
do until lr = ds.tables("details).rows.count - 1
if ds.tables("master").rows(1)(1) =
ds.tables("details").rows(lr)(1) then
ds.tables("details").rows(lr).delete
else
lr +=1
end if
loop
end if
///
So it can not be that difficult to show your code.

Cor
"Brad" <Br**@discussions.microsoft.com> schreef in bericht
news:00**********************************@microsof t.com...
>I have written some code to manipulate data/records in a MASTER (order
> header) and DETAIL (order details) tables.
>
> What I have written is too extensive to post but essentially trying to:
>
> 1. Assign to a datarow (dr1) the first record of the MASTER table
> 2. Assign to another datarow (dr2) the second record of the MASTER
> table
> 3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop
> 4. Assign to a third datarow (dr3) the first record of the DETAIL table
> 5. If dr2.field2 = dr3.field2, then delete record, otherwise repeat
> this
> step till last record incrementing the datarow (dr3) for the DETAIL
> table
> .
>
> What is happening is that dr3.field2 contains the value of dr1.field2!
> Some
> how the values in the first datarow are ending up in the third datarow.
>
> How could this be possible?
>
> I have not set any relations between the tables as I do not believe it
> is
> necessary
>
> -
> Brad
> Sydney, Australia


Nov 21 '05 #9
Cor,
Hi. Thanks for the info. They are good references. I cannot make the VB.NEt
resrouce kit work as I have not enable the IIS.

I have rewritten the code and it now works except that I am struggling to do
the UPDATE.
Thanks
Brad

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Juergen Gerner | last post by:
Hello Python fans, I'm trying and searching for many days for an acceptable solution... without success. I want to store files in a database using BLOB fields. The database table has an ID field...
26
by: Radith | last post by:
Hi All, I have got this task which I cant get my head around: It asks how I would store information: I just want to get an opinion from the group: So here's the question: " You have been...
1
by: George Durzi | last post by:
Don't know why I'm having trouble with this: Dim arNewsletters As DataRow() = dsPubs.Tables(0).Select("CategoryName = 'Newsletters'") If (arNewsletters.Length > 0) Then...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
5
by: David Beck | last post by:
I have a need to store PDF, TIF and other files in TEXT fields on my SQL2000 Server and them retreive them and restore them to the disk (VB6). I created a table CIP_DOCUMENT_ID int no 4...
0
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
3
by: Mark | last post by:
I'm consuming a webservice that makes a simple object available. The object class is marked in the web service as . I have a web application that consumes and uses this web service's class. When...
3
by: creator_bob | last post by:
How do I create an array of datarows from a sorted list? I put a bunch of datarows into a sorted list to sort them. Then I got an array of the sorted elements. However, I cannot typecast them. ...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.