473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

startp up object

hi all,
i am using the following:
Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\MyFolder\data1.mdb;" & "Jet OLEDB:Database Password=" & ""

'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

I am trying to set the database connection from the Sub Main(). now when i
go to project properties, i selected Sub Main as the startup object but it
will show for a while and unload itself quickly. i used to do it in VB6 all
the time but i am now with VB.NET 2003 i am a bit confused. how can i force
the project to start from the Sub Main()?

thanks alot
Jul 19 '05 #1
5 1997
It sounds like (or reads like) you are new to .NET. I believe that your Sub
Main is being called but your form isn't.

All the code that you wrote below looks like typical VB 6 code, but VB.NET
isn't just VB 7.0, it's a complete re-write of the architecture and
therefore the language as well.

You're using classic ADO, trying to set a client-side cursor when you could
be using ADO.NET that natively works with disconnected data.

You're calling the show method of your form, but where is it's
instantiation?
"hkadhim" <ha******@canada.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
hi all,
i am using the following:
Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\MyFolder\data1.mdb;" & "Jet OLEDB:Database Password=" & ""

'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

I am trying to set the database connection from the Sub Main(). now when i
go to project properties, i selected Sub Main as the startup object but it
will show for a while and unload itself quickly. i used to do it in VB6 all the time but i am now with VB.NET 2003 i am a bit confused. how can i force the project to start from the Sub Main()?

thanks alot

Jul 19 '05 #2
thanks Scott for your reply,
you are right, i am new to the .NET world and its a bit confusing!
this is the entire class:
Imports ADODB

Imports System.Data.OleDb

Imports System.Data.SqlClient

Module OpenDBConnection

Public MyfrmLogin As New frmLogin

Dim MyfrmMain As New frmMain

Dim cnn As New ADODB.Connection

Dim rsControl As New ADODB.Recordset

Dim strSQL As String 'this is the source

Dim strPath As String = Application.StartupPath()

Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\MyFolder\Data1.mdb;" & "Jet OLEDB:Database Password=" & ""

'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Application.Run() 'added this line and was able to keep the apllication
running

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

Public Sub LogonProcess()

Dim UserLogin, UserPass As String

UserLogin = MyfrmLogin.txtUserName.Text.Trim()

UserPass = MyfrmLogin.txtPassword.Text.Trim()

Try

rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

strSQL = "SELECT * FROM Employees WHERE Username = '" & UserLogin & "' AND
Password = '" & UserPass & "'"

rsControl.Open(strSQL, cnn, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText) 'compiler gives
me an error in this line

With rsControl

If Not .EOF And Not .BOF Then

MyfrmMain.Show()

MyfrmLogin.Hide()

Else

MsgBox("Your login details are INCORRECT.")

End If

End With

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

End Module

I added Application.Run() and was able to keep the application running. but
now when i try to open the recordset the program terminates and i get an
exception error. do you see anything wrong in this line:

rsControl.Open(strSQL, cnn, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText) 'compiler gives
me an error in this line

thanks a lot

"Scott M." <s-***@badspamsnet.net> wrote in message
news:uN*************@TK2MSFTNGP10.phx.gbl...
It sounds like (or reads like) you are new to .NET. I believe that your Sub Main is being called but your form isn't.

All the code that you wrote below looks like typical VB 6 code, but VB.NET
isn't just VB 7.0, it's a complete re-write of the architecture and
therefore the language as well.

You're using classic ADO, trying to set a client-side cursor when you could be using ADO.NET that natively works with disconnected data.

You're calling the show method of your form, but where is it's
instantiation?
"hkadhim" <ha******@canada.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
hi all,
i am using the following:
Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\MyFolder\data1.mdb;" & "Jet OLEDB:Database Password=" & ""
'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

I am trying to set the database connection from the Sub Main(). now when i go to project properties, i selected Sub Main as the startup object but it will show for a while and unload itself quickly. i used to do it in VB6

all
the time but i am now with VB.NET 2003 i am a bit confused. how can i

force
the project to start from the Sub Main()?

thanks alot


Jul 19 '05 #3
See Chris's reply below to start your form. What I still don't get though
is why you are using ADO at all. You are importing the new ADO.NET
namespaces (and you get references to these assemblies automatically anyway)
so why not just use ADO.NET for better performance and say goodbye to
classic ADO.
"hkadhim" <ha******@canada.com> wrote in message
news:eL*************@tk2msftngp13.phx.gbl...
thanks Scott for your reply,
you are right, i am new to the .NET world and its a bit confusing!
this is the entire class:
Imports ADODB

Imports System.Data.OleDb

Imports System.Data.SqlClient

Module OpenDBConnection

Public MyfrmLogin As New frmLogin

Dim MyfrmMain As New frmMain

Dim cnn As New ADODB.Connection

Dim rsControl As New ADODB.Recordset

Dim strSQL As String 'this is the source

Dim strPath As String = Application.StartupPath()

Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\MyFolder\Data1.mdb;" & "Jet OLEDB:Database Password=" & ""

'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Application.Run() 'added this line and was able to keep the apllication
running

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

Public Sub LogonProcess()

Dim UserLogin, UserPass As String

UserLogin = MyfrmLogin.txtUserName.Text.Trim()

UserPass = MyfrmLogin.txtPassword.Text.Trim()

Try

rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

strSQL = "SELECT * FROM Employees WHERE Username = '" & UserLogin & "' AND
Password = '" & UserPass & "'"

rsControl.Open(strSQL, cnn, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText) 'compiler gives
me an error in this line

With rsControl

If Not .EOF And Not .BOF Then

MyfrmMain.Show()

MyfrmLogin.Hide()

Else

MsgBox("Your login details are INCORRECT.")

End If

End With

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

End Module

I added Application.Run() and was able to keep the application running. but now when i try to open the recordset the program terminates and i get an
exception error. do you see anything wrong in this line:

rsControl.Open(strSQL, cnn, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText) 'compiler gives
me an error in this line

thanks a lot

"Scott M." <s-***@badspamsnet.net> wrote in message
news:uN*************@TK2MSFTNGP10.phx.gbl...
It sounds like (or reads like) you are new to .NET. I believe that your Sub
Main is being called but your form isn't.

All the code that you wrote below looks like typical VB 6 code, but VB.NET
isn't just VB 7.0, it's a complete re-write of the architecture and
therefore the language as well.

You're using classic ADO, trying to set a client-side cursor when you

could
be using ADO.NET that natively works with disconnected data.

You're calling the show method of your form, but where is it's
instantiation?
"hkadhim" <ha******@canada.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
hi all,
i am using the following:
Public Sub Main()

Try

'set the ado connection string

Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\MyFolder\data1.mdb;" & "Jet OLEDB:Database Password="
& ""
'try to open the ado connection

cnn.Open(strConnection)

'set cursor location of recordset to client...

'rsControl.CursorLocation = ADODB.CursorLocationEnum.adUseClient

MyfrmLogin.Show()

Catch ex As Exception

MessageBox.Show(ex.ToString())

Finally

End Try

End Sub

I am trying to set the database connection from the Sub Main(). now
when
i go to project properties, i selected Sub Main as the startup object
but
it will show for a while and unload itself quickly. i used to do it in

VB6 all
the time but i am now with VB.NET 2003 i am a bit confused. how can i

force
the project to start from the Sub Main()?

thanks alot



Jul 19 '05 #4
thanks Chris for your reply,
do you think if i create a dummy startUp form and make it as the startup
object instead of looping (using application.Run() ) will be better?

thanks alot

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:Xn*****************@207.46.248.16...
"hkadhim" <ha******@canada.com> wrote in
news:eL*************@tk2msftngp13.phx.gbl:

MyfrmLogin.Show()

Application.Run() 'added this line and was able to keep the
apllication running


If you start the app this way, you will have to call Application.Exit in
order to close the app. If you want the app to close when the main form
closes, call it like this:

Application.Run(MyfrmLogin)
--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail

Jul 19 '05 #5
Application.Run() isn't a loop.

This is the preferred way unless you want to set your form as the startup
object and write your connection stuff in the form's load event.

"hkadhim" <ha******@canada.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
thanks Chris for your reply,
do you think if i create a dummy startUp form and make it as the startup
object instead of looping (using application.Run() ) will be better?

thanks alot

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:Xn*****************@207.46.248.16...
"hkadhim" <ha******@canada.com> wrote in
news:eL*************@tk2msftngp13.phx.gbl:

MyfrmLogin.Show()

Application.Run() 'added this line and was able to keep the
apllication running


If you start the app this way, you will have to call Application.Exit in
order to close the app. If you want the app to close when the main form
closes, call it like this:

Application.Run(MyfrmLogin)
--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail


Jul 19 '05 #6

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

Similar topics

6
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what...
15
by: Ville Vainio | last post by:
Pythonic Nirvana - towards a true Object Oriented Environment ============================================================= IPython (by Francois Pinard) recently (next release - changes are...
1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
5
by: hkadhim | last post by:
hi all, i am using the following: Public Sub Main() Try 'set the ado connection string Dim strConnection As String = "Provider=" & "Microsoft.Jet.OLEDB.4.0;" & "Data...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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

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