Accessing another table in Form Event

it really depends on how tolerant you want to be of bad or non-existent data being returned in the query. In the case of the try catch technique, make sure you are not suppressing any genuine errors that might be thrown, or the code does not result in inaccurate data being displayed.

Thanks,
Kunal




________________________________
From: Tony Hughes <thughes281@...>
To: vantage@yahoogroups.com
Sent: Friday, April 3, 2009 10:35:46 AM
Subject: Re: [Vantage] Accessing another table in Form Event



I tried something that seemed to work.
I just wrapped it separately in a Try, and in the Catch, set the nTranQty2 = 0.
It caught all errors I threw at it.
Does this sound like right solution, or better I check for null on the SqlDataReader?

____________ _________ _________ __
From: Tony Hughes <thughes281@yahoo. com>
To: vantage@yahoogroups .com
Sent: Friday, April 3, 2009 10:12:10 AM
Subject: Re: [Vantage] Accessing another table in Form Event

I am 99% of the way there, just one small problem.
if checking for parttran records returns nothing (null) how can I capture that?
I don't know how to capture the null/empty dataset returned error.

The full thing is below, but maybe just looking at this helps:
I want to set the variable nTranQty2 to zero if the cnxDR datareader returns null or dbnull or whatever it is that is returned when the query returns no rows. (nothing I try works)

Thanks for any help

With cnxCMD
..CommandText = cnxSQL2
..Connection = cnxCN
End With

cnxCN.Open()

cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While

cnxDR.Close( )

Code:
============ ========= ========

Dim edv as EpiDataView = CType(oTrans. EpiDataViews( "PartTran" ), EpiDataView)
Dim strJob as String = edv.dataView( edv.Row)( "JobNum")
Dim nTranQty as Single = edv.dataView( edv.Row)( "TranQty" )
Dim nTranQty2 as Single
Dim nQtyComp as Single
Dim cnxString as String = "Server='lottest01' ;Database= 'mfgsys803' ;User Id='sysprogress' ;Password= 'sysprogress' "
Dim cnxSQL as String = "SELECT qtycompleted FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxSQL2 as string = "SELECT sum(tranqty) as qtysum FROM parttran WHERE jobnum = '"& strJob & "' and trantype = 'mfg-stk'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
'nTranQty is value in the Quantity box on the form
' 'MessageBox. Show("What you typed in Quantity box: " & cstr(nTranQty) )
'Sets nTranQty2 to sum of tranqty on Parttran records
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL2
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While
cnxDR.Close( )
' 'MessageBox. Show("Sum of mfg-stk parttran transactions for " & strJob & ": " & cstr(nTranQty2) )

'Sets nQtyComp to job quantity completed
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nQtyComp = cnxDR.GetDecimal( 0) '(cnxDR("qtycomplet ed"))
End While
cnxDR.Close( )
' MessageBox.Show( "Qty Completed on job " & strJob & ": " & cstr(nQtyComp) )

if ((nTranQty2 + nTranQty) > nQtyComp) then
MessageBox.Show( cstr(nTranQty2) & " received in to inventory from this job to date" & vbCR & cstr(nQtyComp) & " completed on the job to date" & vbCR & "Receiving in " & cstr(nTranQty) & " would result in overage." )
edv.dataView( edv.Row)( "TranQty" ) = 0
else
'MessageBox. Show("Correct Amount of transaction: " & edv.dataView( edv.Row)( "TranQty" ) )
end if

Catch ex as Exception
'Dim ErrorMsg as String = ex.ToString( ) & ": " & ex.Message
'MessageBox. Show(ErrorMsg)
Finally
cnxCN.Close( )
End Try

============ ========= ========= end code

____________ _________ _________ __
From: Kunal Ganguly <kunal_vantage@ yahoo.com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:46:12 AM
Subject: Re: [Vantage] Accessing another table in Form Event

couple of ways to do that...

first, just get the value from the corresponding row in the database.

second (and a bit more complex), is to typecast the GUID of the form element to a variable and extracting the contents of the form element. For example -

'declaration
Private WithEvents OrderQtyTxtBox as EpiNumericEditor

'typecasting, note that the GUID is shown in the properties for that form element in vantage customization screen
OrderQtyTxtBox = CType(csm.GetNative ControlReference ("692bd57a- dc19-4f78- b4ad-710a7437878 4"), EpiNumericEditor)

'get the value
MessageBox.Show( OrderQtyTxtBox. Value) or MessageBox.Show( OrderQtyTxtBox. Text)

the really cool thing about the typecasting is that you can trigger events using them too
Private Sub OrderQtyTxtBox_ leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles OrderQtyTxtBox. Leave
if OrderQtyTxtBox. text.length <> 0 then
'do something
End if
End Sub

to answer (2), you will probably need to put in a condition after you copy the value from the datareader to a variable. The easiest way, but not the recommended way, to do this is to simply throw an exception in the code and not do anything when the exception is caught (some coder out there reading this is probably cringing right now). Note that genuine exceptions thrown by bad code or data will be ingored similarly.

One little quirk with the datareader, everything it returns is a character string regardless of the column type in the database, so learn some string formatting and conversion commands.! :)

Thanks,
Kunal

____________ _________ _________ __
From: Tony Hughes <thughes281@ yahoo. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:15:38 AM
Subject: Re: [Vantage] Accessing another table in Form Event

Rob, it works nicely, as long as you don't care about the password exposed there.

Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum" ) = "ABC123" I want to break out and cancel

Private Sub PartTran_BeforeFiel dChange(ByVal sender As object, ByVal args As DataColumnChangeEve ntArgs) Handles PartTran_Column. ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldNam e]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column. ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server' ;Database= 'mfgsys803' ;User Id='id';Password= 'password' "
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
...CommandText = cnxSQL
...Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
MessageBox.Show( cnxDR("partnum" ))
End While
catch
end try

Case Else

End Select

End Sub

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
...CommandText = cnxSQL
...Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
.......
....... (cnxDR("col1" )) .....
.......
End While
catch (ex as exception)
.......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the current form, pull a value out and assign it to a variable in the event handling code of the Form Event?
Absolutely...you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module



Private Sub btnOK2_Click(ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans.EpiDataViews("Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView(edvSpa.Row)("ResourceID")

Dim vJob As String = edvSPA.dataView(edvSpa.Row)("JobNum")

Dim vAssy As String = edvSPA.dataView(edvSpa.Row)("AssemblySeq")

Dim vOper As String = edvSPA.dataView(edvSpa.Row)("OprSeq")

Dim Hooks as Integer = 0



Dim adpJO As JobOperSearchAdapter = New
JobOperSearchAdapter(StartProdForm)

adpJO.BOConnect()



Dim record As Boolean = adpJO.GetByID(vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSet = adpJO.JobOperSearchData

Dim dStd As Decimal =
dsJO.Tables("JobOper").Rows(0)("ProdStandard")

Hooks = Math.Ceiling((dstd*60)/17)

'msgbox(dStd)



adpJO.Dispose()

btnOK.PerformClick()







'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show("Number of Hooks: " & Hooks)

End If







What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.



Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg.com/>

(Click the logo to view our site)



________________________________

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Accessing another table in Form Event




Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?





[Non-text portions of this message have been removed]
In some cases the search adapter might not exist. In which case you will have to use code to extract the data you need, for example -

Imports System.Data.SqlClient
Dim cnxString as String = "Server=[server]; Database=[yourdb]; User Id=[user]; Password=[password]"
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection(cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)


While cnxDR.Read
.....
..... (cnxDR("col1")) .....
.....
End While
catch (ex as exception)
.....
end try

the biggest drawback to this is that you are exposing a username and password used to access the SQL server in the form code.


Thanks,
Kunal




________________________________
From: Rob Bucek <rbucek@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event


Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@yahoogroups .com] On Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
Thank you, Kunal.
Does code like this work from a form event?
and do you know whether omitting ID and password in that connection string will force it to use the system agent ODBC id and password?




________________________________
From: Kunal Ganguly <kunal_vantage@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 9:53:43 AM
Subject: Re: [Vantage] Accessing another table in Form Event


In some cases the search adapter might not exist. In which case you will have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)


While cnxDR.Read
.....
..... (cnxDR("col1" )) .....
.....
End While
catch (ex as exception)
.....
end try

the biggest drawback to this is that you are exposing a username and password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
Nice, I might have to try that one out.



Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg.com/>

(Click the logo to view our site)



________________________________

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups.com
Subject: Re: [Vantage] Accessing another table in Form Event



In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data.SqlClient
Dim cnxString as String = "Server=[server]; Database=[yourdb]; User
Id=[user]; Password=[password]"
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection(cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)


While cnxDR.Read
.....
..... (cnxDR("col1")) .....
.....
End While
catch (ex as exception)
.....
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

________________________________
From: Rob Bucek <rbucek@... <mailto:rbucek%40dsmfg.com> >
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]





[Non-text portions of this message have been removed]
Rob, it works nicely, as long as you don't care about the password exposed there.




Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum") = "ABC123" I want to break out and cancel


Private Sub PartTran_BeforeFieldChange(ByVal sender As object, ByVal args As DataColumnChangeEventArgs) Handles PartTran_Column.ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldName]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column.ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server';Database='mfgsys803';User Id='id';Password='password'"
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection(cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)

While cnxDR.Read
MessageBox.Show(cnxDR("partnum"))
End While
catch
end try


Case Else

End Select

End Sub







________________________________
From: Rob Bucek <rbucek@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event


Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
.....
..... (cnxDR("col1" )) .....
.....
End While
catch (ex as exception)
.....
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
This code will work anywhere you need it to - so long the data to be returned exists (otherwise you get those nasty object reference errors). Just be sure to insert the "Imports" statement at the top of the form.

About the ODBC id and password - I believe so. However, the issue I ran into with using the local ODBC connection was that I would then have to set up separate accounts on the SQL server for each of the users with a ODBC connection (I am not a SQL server expert, there might be a more secure way to do this with minimal hassle).

To keep things simple, the username and password I use has only read permissions, which is still a bit of a security risk.

Thanks,
Kunal




________________________________
From: Tony Hughes <thughes281@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 10:17:21 AM
Subject: Re: [Vantage] Accessing another table in Form Event


Thank you, Kunal.
Does code like this work from a form event?
and do you know whether omitting ID and password in that connection string will force it to use the system agent ODBC id and password?

____________ _________ _________ __
From: Kunal Ganguly <kunal_vantage@ yahoo.com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 9:53:43 AM
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
......
...... (cnxDR("col1" )) .....
......
End While
catch (ex as exception)
......
end try

the biggest drawback to this is that you are exposing a username and password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
I know it was Tony's issue but thanks Kunal, I'm sure ill run into an
occasion where I may need to use that. Ill stick to the adaptors when
they are available but like you said they're not always there.



Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg.com/>

(Click the logo to view our site)



________________________________

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 11:28 AM
To: vantage@yahoogroups.com
Subject: Re: [Vantage] Accessing another table in Form Event



This code will work anywhere you need it to - so long the data to be
returned exists (otherwise you get those nasty object reference errors).
Just be sure to insert the "Imports" statement at the top of the form.

About the ODBC id and password - I believe so. However, the issue I ran
into with using the local ODBC connection was that I would then have to
set up separate accounts on the SQL server for each of the users with a
ODBC connection (I am not a SQL server expert, there might be a more
secure way to do this with minimal hassle).

To keep things simple, the username and password I use has only read
permissions, which is still a bit of a security risk.

Thanks,
Kunal

________________________________
From: Tony Hughes <thughes281@... <mailto:thughes281%40yahoo.com>
>
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Sent: Thursday, April 2, 2009 10:17:21 AM
Subject: Re: [Vantage] Accessing another table in Form Event

Thank you, Kunal.
Does code like this work from a form event?
and do you know whether omitting ID and password in that connection
string will force it to use the system agent ODBC id and password?

____________ _________ _________ __
From: Kunal Ganguly <kunal_vantage@ yahoo.com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 9:53:43 AM
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
......
...... (cnxDR("col1" )) .....
......
End While
catch (ex as exception)
......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]





[Non-text portions of this message have been removed]
Yes. You can either pre-establish a foreign key or subtable view to the table for the app or access it as you would a UD table (using SearchByID code).

Rob

--- On Thu, 4/2/09, Tony Hughes <thughes281@...> wrote:

From: Tony Hughes <thughes281@...>
Subject: [Vantage] Accessing another table in Form Event
To: vantage@yahoogroups.com
Date: Thursday, April 2, 2009, 9:50 AM







Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the current form, pull a value out and assign it to a variable in the event handling code of the Form Event?
couple of ways to do that...

first, just get the value from the corresponding row in the database.

second (and a bit more complex), is to typecast the GUID of the form element to a variable and extracting the contents of the form element. For example -

'declaration
Private WithEvents OrderQtyTxtBox as EpiNumericEditor


'typecasting, note that the GUID is shown in the properties for that form element in vantage customization screen
OrderQtyTxtBox = CType(csm.GetNativeControlReference("692bd57a-dc19-4f78-b4ad-710a74378784"), EpiNumericEditor)

'get the value
MessageBox.Show(OrderQtyTxtBox.Value) or MessageBox.Show(OrderQtyTxtBox.Text)

the really cool thing about the typecasting is that you can trigger events using them too
Private Sub OrderQtyTxtBox_leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles OrderQtyTxtBox.Leave
if OrderQtyTxtBox.text.length <> 0 then
'do something
End if
End Sub

to answer (2), you will probably need to put in a condition after you copy the value from the datareader to a variable. The easiest way, but not the recommended way, to do this is to simply throw an exception in the code and not do anything when the exception is caught (some coder out there reading this is probably cringing right now). Note that genuine exceptions thrown by bad code or data will be ingored similarly.

One little quirk with the datareader, everything it returns is a character string regardless of the column type in the database, so learn some string formatting and conversion commands.! :)

Thanks,
Kunal




________________________________
From: Tony Hughes <thughes281@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 11:15:38 AM
Subject: Re: [Vantage] Accessing another table in Form Event



Rob, it works nicely, as long as you don't care about the password exposed there.

Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum" ) = "ABC123" I want to break out and cancel

Private Sub PartTran_BeforeFiel dChange(ByVal sender As object, ByVal args As DataColumnChangeEve ntArgs) Handles PartTran_Column. ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldNam e]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column. ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server' ;Database= 'mfgsys803' ;User Id='id';Password= 'password' "
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
MessageBox.Show( cnxDR("partnum" ))
End While
catch
end try


Case Else

End Select

End Sub

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
......
...... (cnxDR("col1" )) .....
......
End While
catch (ex as exception)
......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
I am 99% of the way there, just one small problem.
if checking for parttran records returns nothing (null) how can I capture that?
I don't know how to capture the null/empty dataset returned error.

The full thing is below, but maybe just looking at this helps:
I want to set the variable nTranQty2 to zero if the cnxDR datareader returns null or dbnull or whatever it is that is returned when the query returns no rows. (nothing I try works)

Thanks for any help



With cnxCMD
.CommandText = cnxSQL2
.Connection = cnxCN
End With

cnxCN.Open()

cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)

While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal(0) '(cnxDR("qtysum"))
End While

cnxDR.Close()








Code:
=============================


Dim edv as EpiDataView = CType(oTrans.EpiDataViews("PartTran"), EpiDataView)
Dim strJob as String = edv.dataView(edv.Row)("JobNum")
Dim nTranQty as Single = edv.dataView(edv.Row)("TranQty")
Dim nTranQty2 as Single
Dim nQtyComp as Single
Dim cnxString as String = "Server='lottest01';Database='mfgsys803';User Id='sysprogress';Password='sysprogress'"
Dim cnxSQL as String = "SELECT qtycompleted FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxSQL2 as string = "SELECT sum(tranqty) as qtysum FROM parttran WHERE jobnum = '"& strJob & "' and trantype = 'mfg-stk'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
'nTranQty is value in the Quantity box on the form
' 'MessageBox.Show("What you typed in Quantity box: " & cstr(nTranQty))
'Sets nTranQty2 to sum of tranqty on Parttran records
cnxCN = New SqlConnection(cnxString)
With cnxCMD
.CommandText = cnxSQL2
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)
While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal(0) '(cnxDR("qtysum"))
End While
cnxDR.Close()
' 'MessageBox.Show("Sum of mfg-stk parttran transactions for " & strJob & ": " & cstr(nTranQty2))


'Sets nQtyComp to job quantity completed
cnxCN = New SqlConnection(cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReader(CommandBehavior.CloseConnection)
While cnxDR.Read()
nQtyComp = cnxDR.GetDecimal(0) '(cnxDR("qtycompleted"))
End While
cnxDR.Close()
' MessageBox.Show("Qty Completed on job " & strJob & ": " & cstr(nQtyComp))


if ((nTranQty2 + nTranQty) > nQtyComp) then
MessageBox.Show(cstr(nTranQty2) & " received in to inventory from this job to date" & vbCR & cstr(nQtyComp) & " completed on the job to date" & vbCR & "Receiving in " & cstr(nTranQty) & " would result in overage." )
edv.dataView(edv.Row)("TranQty") = 0
else
'MessageBox.Show("Correct Amount of transaction: " & edv.dataView(edv.Row)("TranQty") )
end if

Catch ex as Exception
'Dim ErrorMsg as String = ex.ToString() & ": " & ex.Message
'MessageBox.Show(ErrorMsg)
Finally
cnxCN.Close()
End Try


============================== end code









________________________________
From: Kunal Ganguly <kunal_vantage@...>
To: vantage@yahoogroups.com
Sent: Thursday, April 2, 2009 11:46:12 AM
Subject: Re: [Vantage] Accessing another table in Form Event


couple of ways to do that...

first, just get the value from the corresponding row in the database.

second (and a bit more complex), is to typecast the GUID of the form element to a variable and extracting the contents of the form element. For example -

'declaration
Private WithEvents OrderQtyTxtBox as EpiNumericEditor

'typecasting, note that the GUID is shown in the properties for that form element in vantage customization screen
OrderQtyTxtBox = CType(csm.GetNative ControlReference ("692bd57a- dc19-4f78- b4ad-710a7437878 4"), EpiNumericEditor)

'get the value
MessageBox.Show( OrderQtyTxtBox. Value) or MessageBox.Show( OrderQtyTxtBox. Text)

the really cool thing about the typecasting is that you can trigger events using them too
Private Sub OrderQtyTxtBox_ leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles OrderQtyTxtBox. Leave
if OrderQtyTxtBox. text.length <> 0 then
'do something
End if
End Sub

to answer (2), you will probably need to put in a condition after you copy the value from the datareader to a variable. The easiest way, but not the recommended way, to do this is to simply throw an exception in the code and not do anything when the exception is caught (some coder out there reading this is probably cringing right now). Note that genuine exceptions thrown by bad code or data will be ingored similarly.

One little quirk with the datareader, everything it returns is a character string regardless of the column type in the database, so learn some string formatting and conversion commands.! :)

Thanks,
Kunal

____________ _________ _________ __
From: Tony Hughes <thughes281@yahoo. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:15:38 AM
Subject: Re: [Vantage] Accessing another table in Form Event

Rob, it works nicely, as long as you don't care about the password exposed there.

Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum" ) = "ABC123" I want to break out and cancel

Private Sub PartTran_BeforeFiel dChange(ByVal sender As object, ByVal args As DataColumnChangeEve ntArgs) Handles PartTran_Column. ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldNam e]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column. ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server' ;Database= 'mfgsys803' ;User Id='id';Password= 'password' "
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
MessageBox.Show( cnxDR("partnum" ))
End While
catch
end try

Case Else

End Select

End Sub

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
......
...... (cnxDR("col1" )) .....
......
End While
catch (ex as exception)
......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
I tried something that seemed to work.
I just wrapped it separately in a Try, and in the Catch, set the nTranQty2 = 0.
It caught all errors I threw at it.
Does this sound like right solution, or better I check for null on the SqlDataReader?




________________________________
From: Tony Hughes <thughes281@...>
To: vantage@yahoogroups.com
Sent: Friday, April 3, 2009 10:12:10 AM
Subject: Re: [Vantage] Accessing another table in Form Event


I am 99% of the way there, just one small problem.
if checking for parttran records returns nothing (null) how can I capture that?
I don't know how to capture the null/empty dataset returned error.

The full thing is below, but maybe just looking at this helps:
I want to set the variable nTranQty2 to zero if the cnxDR datareader returns null or dbnull or whatever it is that is returned when the query returns no rows. (nothing I try works)

Thanks for any help

With cnxCMD
.CommandText = cnxSQL2
.Connection = cnxCN
End With

cnxCN.Open()

cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While

cnxDR.Close( )

Code:
============ ========= ========

Dim edv as EpiDataView = CType(oTrans. EpiDataViews( "PartTran" ), EpiDataView)
Dim strJob as String = edv.dataView( edv.Row)( "JobNum")
Dim nTranQty as Single = edv.dataView( edv.Row)( "TranQty" )
Dim nTranQty2 as Single
Dim nQtyComp as Single
Dim cnxString as String = "Server='lottest01' ;Database= 'mfgsys803' ;User Id='sysprogress' ;Password= 'sysprogress' "
Dim cnxSQL as String = "SELECT qtycompleted FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxSQL2 as string = "SELECT sum(tranqty) as qtysum FROM parttran WHERE jobnum = '"& strJob & "' and trantype = 'mfg-stk'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
'nTranQty is value in the Quantity box on the form
' 'MessageBox. Show("What you typed in Quantity box: " & cstr(nTranQty) )
'Sets nTranQty2 to sum of tranqty on Parttran records
cnxCN = New SqlConnection( cnxString)
With cnxCMD
.CommandText = cnxSQL2
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While
cnxDR.Close( )
' 'MessageBox. Show("Sum of mfg-stk parttran transactions for " & strJob & ": " & cstr(nTranQty2) )


'Sets nQtyComp to job quantity completed
cnxCN = New SqlConnection( cnxString)
With cnxCMD
.CommandText = cnxSQL
.Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nQtyComp = cnxDR.GetDecimal( 0) '(cnxDR("qtycomplet ed"))
End While
cnxDR.Close( )
' MessageBox.Show( "Qty Completed on job " & strJob & ": " & cstr(nQtyComp) )

if ((nTranQty2 + nTranQty) > nQtyComp) then
MessageBox.Show( cstr(nTranQty2) & " received in to inventory from this job to date" & vbCR & cstr(nQtyComp) & " completed on the job to date" & vbCR & "Receiving in " & cstr(nTranQty) & " would result in overage." )
edv.dataView( edv.Row)( "TranQty" ) = 0
else
'MessageBox. Show("Correct Amount of transaction: " & edv.dataView( edv.Row)( "TranQty" ) )
end if

Catch ex as Exception
'Dim ErrorMsg as String = ex.ToString( ) & ": " & ex.Message
'MessageBox. Show(ErrorMsg)
Finally
cnxCN.Close( )
End Try

============ ========= ========= end code

____________ _________ _________ __
From: Kunal Ganguly <kunal_vantage@ yahoo.com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:46:12 AM
Subject: Re: [Vantage] Accessing another table in Form Event

couple of ways to do that...

first, just get the value from the corresponding row in the database.

second (and a bit more complex), is to typecast the GUID of the form element to a variable and extracting the contents of the form element. For example -

'declaration
Private WithEvents OrderQtyTxtBox as EpiNumericEditor

'typecasting, note that the GUID is shown in the properties for that form element in vantage customization screen
OrderQtyTxtBox = CType(csm.GetNative ControlReference ("692bd57a- dc19-4f78- b4ad-710a7437878 4"), EpiNumericEditor)

'get the value
MessageBox.Show( OrderQtyTxtBox. Value) or MessageBox.Show( OrderQtyTxtBox. Text)

the really cool thing about the typecasting is that you can trigger events using them too
Private Sub OrderQtyTxtBox_ leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles OrderQtyTxtBox. Leave
if OrderQtyTxtBox. text.length <> 0 then
'do something
End if
End Sub

to answer (2), you will probably need to put in a condition after you copy the value from the datareader to a variable. The easiest way, but not the recommended way, to do this is to simply throw an exception in the code and not do anything when the exception is caught (some coder out there reading this is probably cringing right now). Note that genuine exceptions thrown by bad code or data will be ingored similarly.

One little quirk with the datareader, everything it returns is a character string regardless of the column type in the database, so learn some string formatting and conversion commands.! :)

Thanks,
Kunal

____________ _________ _________ __
From: Tony Hughes <thughes281@ yahoo. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:15:38 AM
Subject: Re: [Vantage] Accessing another table in Form Event

Rob, it works nicely, as long as you don't care about the password exposed there.

Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum" ) = "ABC123" I want to break out and cancel

Private Sub PartTran_BeforeFiel dChange(ByVal sender As object, ByVal args As DataColumnChangeEve ntArgs) Handles PartTran_Column. ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldNam e]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column. ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server' ;Database= 'mfgsys803' ;User Id='id';Password= 'password' "
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
MessageBox.Show( cnxDR("partnum" ))
End While
catch
end try

Case Else

End Select

End Sub

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
......
...... (cnxDR("col1" )) .....
......
End While
catch (ex as exception)
......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]
you could try comparing the value to either Nothing or "". For example -

If myvar <> Nothing Then....

If myvar <> "" Then ...
If myvar.length <> 0 then ... (the database returns a string, so if the length is zero, then null was returned)

if myvar was declared as string, and the above returned an error, then try declaring myvar simply as "Dim myvar" and not assigning it a data type.

you could also try using functions like IsEmpty, IsNothing or IsNull. These functions can get a bit tricky though, as the epicor flavor of visual basic has horrible garbage collection.

Thanks,
Kunal




________________________________
From: Tony Hughes <thughes281@...>
To: vantage@yahoogroups.com
Sent: Friday, April 3, 2009 10:12:10 AM
Subject: Re: [Vantage] Accessing another table in Form Event


I am 99% of the way there, just one small problem.
if checking for parttran records returns nothing (null) how can I capture that?
I don't know how to capture the null/empty dataset returned error.

The full thing is below, but maybe just looking at this helps:
I want to set the variable nTranQty2 to zero if the cnxDR datareader returns null or dbnull or whatever it is that is returned when the query returns no rows. (nothing I try works)

Thanks for any help

With cnxCMD
..CommandText = cnxSQL2
..Connection = cnxCN
End With

cnxCN.Open()

cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While

cnxDR.Close( )

Code:
============ ========= ========

Dim edv as EpiDataView = CType(oTrans. EpiDataViews( "PartTran" ), EpiDataView)
Dim strJob as String = edv.dataView( edv.Row)( "JobNum")
Dim nTranQty as Single = edv.dataView( edv.Row)( "TranQty" )
Dim nTranQty2 as Single
Dim nQtyComp as Single
Dim cnxString as String = "Server='lottest01' ;Database= 'mfgsys803' ;User Id='sysprogress' ;Password= 'sysprogress' "
Dim cnxSQL as String = "SELECT qtycompleted FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxSQL2 as string = "SELECT sum(tranqty) as qtysum FROM parttran WHERE jobnum = '"& strJob & "' and trantype = 'mfg-stk'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
'nTranQty is value in the Quantity box on the form
' 'MessageBox. Show("What you typed in Quantity box: " & cstr(nTranQty) )
'Sets nTranQty2 to sum of tranqty on Parttran records
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL2
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nTranQty2 = cnxDr.GetDecimal( 0) '(cnxDR("qtysum" ))
End While
cnxDR.Close( )
' 'MessageBox. Show("Sum of mfg-stk parttran transactions for " & strJob & ": " & cstr(nTranQty2) )


'Sets nQtyComp to job quantity completed
cnxCN = New SqlConnection( cnxString)
With cnxCMD
..CommandText = cnxSQL
..Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)
While cnxDR.Read()
nQtyComp = cnxDR.GetDecimal( 0) '(cnxDR("qtycomplet ed"))
End While
cnxDR.Close( )
' MessageBox.Show( "Qty Completed on job " & strJob & ": " & cstr(nQtyComp) )

if ((nTranQty2 + nTranQty) > nQtyComp) then
MessageBox.Show( cstr(nTranQty2) & " received in to inventory from this job to date" & vbCR & cstr(nQtyComp) & " completed on the job to date" & vbCR & "Receiving in " & cstr(nTranQty) & " would result in overage." )
edv.dataView( edv.Row)( "TranQty" ) = 0
else
'MessageBox. Show("Correct Amount of transaction: " & edv.dataView( edv.Row)( "TranQty" ) )
end if

Catch ex as Exception
'Dim ErrorMsg as String = ex.ToString( ) & ": " & ex.Message
'MessageBox. Show(ErrorMsg)
Finally
cnxCN.Close( )
End Try

============ ========= ========= end code

____________ _________ _________ __
From: Kunal Ganguly <kunal_vantage@ yahoo.com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:46:12 AM
Subject: Re: [Vantage] Accessing another table in Form Event

couple of ways to do that...

first, just get the value from the corresponding row in the database.

second (and a bit more complex), is to typecast the GUID of the form element to a variable and extracting the contents of the form element. For example -

'declaration
Private WithEvents OrderQtyTxtBox as EpiNumericEditor

'typecasting, note that the GUID is shown in the properties for that form element in vantage customization screen
OrderQtyTxtBox = CType(csm.GetNative ControlReference ("692bd57a- dc19-4f78- b4ad-710a7437878 4"), EpiNumericEditor)

'get the value
MessageBox.Show( OrderQtyTxtBox. Value) or MessageBox.Show( OrderQtyTxtBox. Text)

the really cool thing about the typecasting is that you can trigger events using them too
Private Sub OrderQtyTxtBox_ leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles OrderQtyTxtBox. Leave
if OrderQtyTxtBox. text.length <> 0 then
'do something
End if
End Sub

to answer (2), you will probably need to put in a condition after you copy the value from the datareader to a variable. The easiest way, but not the recommended way, to do this is to simply throw an exception in the code and not do anything when the exception is caught (some coder out there reading this is probably cringing right now). Note that genuine exceptions thrown by bad code or data will be ingored similarly.

One little quirk with the datareader, everything it returns is a character string regardless of the column type in the database, so learn some string formatting and conversion commands.! :)

Thanks,
Kunal

____________ _________ _________ __
From: Tony Hughes <thughes281@ yahoo. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 11:15:38 AM
Subject: Re: [Vantage] Accessing another table in Form Event

Rob, it works nicely, as long as you don't care about the password exposed there.

Below is my code, I am almost there, thank you!
2 more questions.

1. how do I assign the value of a text box (txtJob) to a variable? (isn't this VB syntax?)

2. how do I cancel the _BeforeFieldChange based on the return value?
in this example, if cnxDR("partnum" ) = "ABC123" I want to break out and cancel

Private Sub PartTran_BeforeFiel dChange(ByVal sender As object, ByVal args As DataColumnChangeEve ntArgs) Handles PartTran_Column. ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldNam e]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'

Select Case args.Column. ColumnName

Case "TranQty"
Dim strJob as String = txtJob.Text
Dim cnxString as String = "Server='server' ;Database= 'mfgsys803' ;User Id='id';Password= 'password' "
Dim cnxSQL as String = "SELECT partnum FROM jobhead WHERE jobnum = '" & strJob & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
...CommandText = cnxSQL
...Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
MessageBox.Show( cnxDR("partnum" ))
End While
catch
end try

Case Else

End Select

End Sub

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com>
To: vantage@yahoogroups .com
Sent: Thursday, April 2, 2009 10:20:20 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Nice, I might have to try that one out.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On Behalf
Of Kunal Ganguly
Sent: Thursday, April 02, 2009 9:54 AM
To: vantage@yahoogroups .com
Subject: Re: [Vantage] Accessing another table in Form Event

In some cases the search adapter might not exist. In which case you will
have to use code to extract the data you need, for example -

Imports System.Data. SqlClient
Dim cnxString as String = "Server=[server] ; Database=[yourdb] ; User
Id=[user]; Password=[password] "
Dim cnxSQL as String = "SELECT [columns]" & _
" FROM [table] " & _
" WHERE [column] = '" & [static value or something from the form] & "'"
Dim cnxCN as SqlConnection
Dim cnxCMD as New SqlCommand
Dim cnxDR as SqlDataReader

Try
cnxCN = New SqlConnection( cnxString)
With cnxCMD
...CommandText = cnxSQL
...Connection = cnxCN
End With
cnxCN.Open()
cnxDR = cnxCMD.ExecuteReade r(CommandBehavio r.CloseConnectio n)

While cnxDR.Read
.......
....... (cnxDR("col1" )) .....
.......
End While
catch (ex as exception)
.......
end try

the biggest drawback to this is that you are exposing a username and
password used to access the SQL server in the form code.

Thanks,
Kunal

____________ _________ _________ __
From: Rob Bucek <rbucek@dsmfg. com <mailto:rbucek% 40dsmfg.com> >
To: vantage@yahoogroups .com <mailto:vantage% 40yahoogroups. com>
Sent: Thursday, April 2, 2009 9:04:40 AM
Subject: RE: [Vantage] Accessing another table in Form Event

Absolutely.. .you do have to have some associated way to link the
records, otherwise I assume you would be talking about a static value
and not a variable existing in another table based off of some value in
the current record set youre working with in a form. If I understand
what youre looking for perhaps this would be an example... this resides
in our start activity form under the MES module

Private Sub btnOK2_Click( ByVal Sender As Object, ByVal Args As
System.EventArgs) Handles btnOK2.Click

'// ** Place Event Handling Code Here **

Dim edvSPA As EpiDataView = CType(oTrans. EpiDataViews( "Start"),
EpiDataView)

Dim vRes As String = edvSPA.dataView( edvSpa.Row) ("ResourceID" )

Dim vJob As String = edvSPA.dataView( edvSpa.Row) ("JobNum" )

Dim vAssy As String = edvSPA.dataView( edvSpa.Row) ("AssemblySeq" )

Dim vOper As String = edvSPA.dataView( edvSpa.Row) ("OprSeq" )

Dim Hooks as Integer = 0

Dim adpJO As JobOperSearchAdapte r = New
JobOperSearchAdapte r(StartProdForm)

adpJO.BOConnect( )

Dim record As Boolean = adpJO.GetByID( vJob, vAssy, vOper)

Dim dsJO As JobOperSearchDataSe t = adpJO.JobOperSearch Data

Dim dStd As Decimal =
dsJO.Tables( "JobOper" ).Rows(0) ("ProdStandard" )

Hooks = Math.Ceiling( (dstd*60) /17)

'msgbox(dStd)

adpJO.Dispose( )

btnOK.PerformClick( )

'msgbox(vRes)

If vRes = "PMB" Then

MessageBox.Show( "Number of Hooks: " & Hooks)

End If

What we are doing here is when an operator logs into a job on our paint
line (hence the reference to the operation code) it goes to the job oper
table to get the production standard, does some math and comes back with
a message box translating for him the amount of space on the line (in
hooks), that the part will occupy. The button references are that I
replaced the standard 'ok' button on the form. This is probably
irrelevant to what you will be doing. The key is the search adapter,
most if not all tables should have a method available to search a
record. Hope this helps.

Rob Bucek

Manufacturing Engineer

PH: 715-284-5376 ext 311

FAX: 715-284-4084

<http://www.dsmfg com/>

(Click the logo to view our site)

____________ _________ _________ __

From: vantage@yahoogroups .com [mailto:vantage@ yahoogroups .com] On
Behalf
Of Tony Hughes
Sent: Thursday, April 02, 2009 8:51 AM
To: vantage@yahoogroups .com
Subject: [Vantage] Accessing another table in Form Event

Can I access another table in Form Event code?
I want to open a table that has nothing to do with the tables behind the
current form, pull a value out and assign it to a variable in the event
handling code of the Form Event?

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]







[Non-text portions of this message have been removed]