|
Try this:
Try<br />
'Code...etc<br />
Catch ex as exception<br />
messagebox.show(ex.message)<br />
end try
you can change it to try finally statment or whatever.
Posted by The ANZAC
|
|
|
|
|
TRY
in this block you write ur code and also the messages you would like to be displayed to the users.
when some exception is fired then it goes to the catch block.
Catch
in this you write what has to be done when particular exception is fired.
for example while saving if exception is fired then you can rollback the transaction.
Finally
and in this block what ever you will write will be executed no matter what happens.
Mohinder Singh
|
|
|
|
|
This is the format I use
Try
'Code that can cause problems
Catch ex As System.Exception
'ex.Message - Give you the error message
'ex.StackTrace - Gives you more details on the error, like what line number caused it.
' These are great for trouble shooting your app at design time
Finally
'Cleanup code that runs no matter what happens, even if App shuts down
End Try
My Question to add to this subjet would be : How do you Identify a particular Exception? (ex: File Not Found)
In the old "On Error..." statment it reported an error message and error number, the number could then be used in a IF or SELECT CASE statment. In the new TRY...CATCH the only way I have found was to check for the message witch can be a very long string.
Hope this helps you.....and me!!!!
Rob
|
|
|
|
|
Thanks Christian Graus, The ANZAC , vengaqua, and roo426. now I got to know what is this Try-catch techonolgy. I googled for this but they are explaining using some samples those are really very standard (i should say very hard for a newbie). I am new to this technology; I was confused when I saw their code.
I am learning a lot using this codeproject site.
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
I'm having a hell of a time trying to figure out how to connect to an MS Access database on a server on the local LAN. I'm using OLE and I can get it to connect if A) The database is on the local machine, or B) The database is in a shared folder on the remote machine and the folder is mapped to the system running the program. I would very much like to not have to have the folder mapped. Having to share the folder isn't too big of a problem.
Can anyone help me? I've been googling and asking around for 2-3 days now. I would very much like to be able to stick with OLE since switching would possibly mean re-writing all my database related code on 4-5 forms.
|
|
|
|
|
Your only other option is to use the UNC path to the file in your connection string. Essentially the same path that the drive latter is mapped to.
\\server\share\folder\folder\database.mdb
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
The server name is a1531sbits
The folder the database is in is in a folder named Databases in C:\
The folder has a share name of Databases$ with Permissions set to give everyone full access (This will change later and only certain users will have that ability)
The database name is users
I've tried the following as the file path in the connection string:
\\a1531sbits\Databases$\users.mdb
I've also tried
\\a1531sbits\Databases\users.mdb
Neither work. What am I doing wrong?
|
|
|
|
|
There are two sets of permissions. The Share permissions and the NTFS folder permissions. If you need people to use an Access database, both of these sets of permissions must allow Read, Write, FileCreate, Erase. Basically, full rights. You cannot have just Read permissions for some user who use the app because an Access database won't work at all without full rights to the folder the database is in.
Are your Windows machines setup in a Workgroup or Domain config? Basically, you to understand Windows networking. That's not something that can be taught in a forum environment.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Yeah, I understand networking, wouldn't have my Net+ if I didn't. The computers I'm testing on here at home are set up in a workgroup, but the systems the program and database are going to be running in when I'm done are going to be in a domain.
|
|
|
|
|
I went and changed the security settings on the folder and tried again, but it didn't work. I got this error message (after removing my Try..Catch statements)
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.windows.forms.dll
Additional information: No error information available: DB_SEC_E_AUTH_FAILED(0x80040E4D)."
|
|
|
|
|
Did you password protect your Access database or enable workgroup security in it?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I did a while ago, but I wasn't able to get connection strings to work with it so I removed them.
|
|
|
|
|
fatali8 wrote: so I removed them.
Something got missed because that's where the security failure is comming from.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
No, I got them all. I figured out what happened. For some reason my connection to the server got messed up somehow.. I could Remote Desktop to it, but I couldn't map any shared drives/folders and I couldn't access any of my previously mapped drives. I've had it happen before, and I'm pretty sure it has something to do with the fact that when I turn off my PC I Hibernate it, mainly because I have work open and don't want to wait for them to all open up again. As well as that, I missed a part in my connection string that had username and password information from when I was trying to connect to a DB with a DB password. That kind of mistake makes you want to say "idiot" doesn't it? lol.
Anyway, now after a restart I got it to work. Thanks for all the help. I got more help from you than I did in all of the other 4-5 forums I've asked in combined. From now on I'll just come here when I need to ask a question. Again, thanks.
|
|
|
|
|
Hello All!
I have two forms in a project. vb.net. I just want to take the value from 1 textbox on a form, and put it in a string in another from.
My code.
Public Sub frmGoodLuck_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim MainFrm As New Mainfrm<br />
<br />
lblGoodLuck.Text = ("$" & MainFrm.txtTblID.Text.ToString & " has been added. & Good Luck!!")<br />
<br />
End Sub<br />
End Class
What am I doing wrong?
Thanks! Rudy
|
|
|
|
|
2 quick questions. Did you get an error message? And does the label txtTblID exist on MainFrm ?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Hi Matrix!
No error. and lblTblID does exsisit on Mainfrm.
Thanks!
Rudy
|
|
|
|
|
Well, I'm not sure what the problem is. But here are a few steps that might fix it:
1. Make sure that there's pre or otherwise set text in txtTblID .
2. Try saving your text to a variable, then reading the variable from your label.
And, what exactly happens when you try to set text to your label? Is the label just blank?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
It's blank, because he's getting his value from a newly created instance of the form.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You are creating a new instance of the Mainfrm class. That instance will work independently from the one that already exists.
You have to use a reference to the form that already exists in order to access it's controls.
---
Year happy = new Year(2007);
|
|
|
|
|
Hi Guffa!
Could you give me a quick example.
1) myMainfrm.Show()
myMainfrm.GetTblID(Me) NAME OF FORM <"loggonfrm">
2)Public Sub GetTblID(ByVal TblID As Loginfrm)
txtTblID.Text = TblID.txtTableid.Text
End Sub NAME OF FORM<"Mainfrm">
Something like this?
Thanks!
Rudy
|
|
|
|
|
No - do NOT do this. Do NOT make your form elements public.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Well, your whole approach is wrong, your controls should not be made public. Instead, expose a property called TblId, or whatever.
rudemusik wrote: Dim MainFrm As New Mainfrm
This is your problem. You're creating a new MainFrm instance, which as no text on it. It's a different instance to the one that contains the text you want. You could get around this with a static property, or you can set up delegates to pass the info. It looks to me in this instance that you should either pass the value of the text to a constructor, or set a property that sets the GoodLuck label on this form, as MainFrm is obviously the class creating this one, and as you're handling the load event, it's obvious you want to set the text when the form opens.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thanks Chris!
I see where my problem is. So what are some of the reasons I don't want to use Public? I never gave it much thought. What harm could it do?
Thanks!
Rudy
|
|
|
|
|
It's just bad practise. The whole point of OO is to write objects that hide their inner workings. Expose only what you need to, which in this case, is a string, not a textbox.
IT's not that your program won't work, just that it's better to form good habits.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|