This is a multi-part message in MIME format.
------=_NextPart_000_00A0_01C4A706.62151E10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I am developing a custom application for Microstation v8. My app =
connects to an Access database (I haven't yet hooked it up to =
Microstation).
Within my code I have two very similar functions to query a database for =
a particular record. They are:
Public Function GetProjCfgFromDb(ByVal lProjID As Long) As String
Try
'connection stuff
Dim Conn As New OleDbConnection(sConnString & dbFullPath)
Dim strSQL As String =3D "SELECT proj_cfg FROM tbl_projects =
WHERE proj_id =3D " & lProjID
Dim Cmd As New OleDbCommand(strSQL, Conn)
Conn.Open()
GetProjCfgFromDb =3D CType(Cmd.ExecuteScalar(), String)
'cleanup
Conn.Dispose()
Conn =3D Nothing
Cmd.Dispose()
Cmd =3D Nothing
Catch ex As Exception
MsgBox(ex.Source & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
Public Function GetProjIDFromDb(ByVal sProjCfg As String) As Long
Try
'connection stuff
Dim Conn As New OleDbConnection(sConnString & dbFullPath)
Dim strSQL As String =3D "SELECT proj_id FROM tbl_projects =
WHERE proj_cfg =3D " & sProjCfg
Dim Cmd As New OleDbCommand(strSQL, Conn)
Conn.Open()
GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)
'cleanup
Conn.Dispose()
Conn =3D Nothing
Cmd.Dispose()
Cmd =3D Nothing
Catch ex As Exception
MsgBox(ex.Source & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
=20
=20
This first function is called like this:
Dim sProjConfig As String
sProjConfig =3D GetProjCfgFromDb(CLng(Me.cboProjects.SelectedValue))
and works perfectly, but the second function is called like this:
Private Sub CheckForProject()
If IsProcessExecuting("ustation") =3D False Then
projectForm =3D New frmProj
projectForm.ShowDialog()
Else
'process is executing so get the project
'configuration file currently selected
'and set project ID from database
oMSTN =3D New MicrostationDGN.Application
Dim sConfigName As String
sConfigName =3D =
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME")
lProj_ID =3D GetProjIDFromDb(sConfigName)
End If
End Sub
where =
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME") =
returns a string (eg "SRA 1957 BGS Lower School"). =20
GetProjIDFromDb() fails ion this line:
GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)
I have checked all the obvious things but I cannot see what is causing =
the error.
Please help
Russ
------=_NextPart_000_00A0_01C4A706.62151E10
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am developing a custom application =
for=20
Microstation v8. My app connects to an Access database (I haven't yet =
hooked it=20
up to Microstation).</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Within my code I have two very similar =
functions to=20
query a database for a particular record. They are:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> Public Function=20
GetProjCfgFromDb(ByVal lProjID As Long) As=20
String<BR> =20
Try<BR> =
=20
'connection=20
stuff<BR> &nbs=
p; Dim=20
Conn As New OleDbConnection(sConnString &=20
dbFullPath)<BR> &nbs=
p; =20
Dim strSQL As String =3D "SELECT proj_cfg FROM tbl_projects WHERE =
proj_id =3D "=20
&=20
lProjID<BR> &n=
bsp;=20
Dim Cmd As New OleDbCommand(strSQL,=20
Conn)<BR> &nbs=
p;=20
Conn.Open()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p;=20
GetProjCfgFromDb =3D CType(Cmd.ExecuteScalar(), String)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p;=20
'cleanup<BR> &=
nbsp;=20
Conn.Dispose()<BR> &=
nbsp; =20
Conn =3D=20
Nothing<BR> &n=
bsp;=20
Cmd.Dispose()<BR> &n=
bsp; =20
Cmd =3D Nothing</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> Catch ex=20
As=20
Exception<BR> =
=20
MsgBox(ex.Source & ex.Message,=20
MsgBoxStyle.Critical)<BR> End=20
Try<BR> End Function</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> Public Function=20
GetProjIDFromDb(ByVal sProjCfg As String) As=20
Long<BR> =20
Try<BR> =
=20
'connection=20
stuff<BR> &nbs=
p; Dim=20
Conn As New OleDbConnection(sConnString &=20
dbFullPath)<BR> &nbs=
p; =20
Dim strSQL As String =3D "SELECT proj_id FROM tbl_projects WHERE =
proj_cfg =3D "=20
&=20
sProjCfg<BR> &=
nbsp;=20
Dim Cmd As New OleDbCommand(strSQL,=20
Conn)<BR> &nbs=
p;=20
Conn.Open()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p;=20
GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p;=20
'cleanup<BR> &=
nbsp;=20
Conn.Dispose()<BR> &=
nbsp; =20
Conn =3D=20
Nothing<BR> &n=
bsp;=20
Cmd.Dispose()<BR> &n=
bsp; =20
Cmd =3D Nothing</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> Catch ex=20
As=20
Exception<BR> =
=20
MsgBox(ex.Source & ex.Message,=20
MsgBoxStyle.Critical)<BR> End=20
Try<BR> End=20
Function<BR> <BR> </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>This first function is called like=20
this:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Dim sProjConfig As =
String<BR>sProjConfig =3D=20
GetProjCfgFromDb(CLng(Me.cboProjects.SelectedValue))</FONT></DIV>
<DIV> </DIV><FONT face=3DArial size=3D2>
<DIV><BR>and works perfectly, but the second function is called like =
this:</DIV>
<DIV> </DIV>
<DIV>Private Sub CheckForProject()<BR> If =
IsProcessExecuting("ustation") =3D=20
False Then<BR> projectForm =3D New=20
frmProj<BR> projectForm.ShowDialog()<BR> Else<BR> &n=
bsp;'process=20
is executing so get the project<BR> 'configuration file =
currently=20
selected<BR> 'and set project ID from =
database<BR> oMSTN =3D=20
New MicrostationDGN.Application</DIV>
<DIV> </DIV>
<DIV> Dim sConfigName As String<BR> sConfigName =
=3D=20
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME")</DI=
V>
<DIV> </DIV>
<DIV> lProj_ID =3D GetProjIDFromDb(sConfigName)<BR> End =
If<BR>End=20
Sub</DIV>
<DIV> </DIV>
<DIV><BR>where=20
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME") =
returns a=20
string (eg "SRA 1957 BGS Lower School"). </DIV>
<DIV> </DIV>
<DIV><BR>GetProjIDFromDb() fails ion this line:</DIV>
<DIV> </DIV>
<DIV>GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)</DIV>
<DIV> </DIV>
<DIV><BR>I have checked all the obvious things but I cannot see what is =
causing=20
the error.</DIV>
<DIV> </DIV>
<DIV>Please help</DIV>
<DIV> </DIV>
<DIV>Russ</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_00A0_01C4A706.62151E10--