473,395 Members | 2,253 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,395 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 1999
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.