Wednesday, October 28, 2009

Browse File on VB.NET

You can do this by using the OpenFileDialog class that is defined in Windows.Forms class. First, you need to add reference to System.Windows.Form.dll library and call using Imports.System.Windows.Forms before using the class.

In this sample code, I'm using OpenFileDialog class to browse a file.

Private fdlg As OpenFileDialog = New OpenFileDialog()
Private fdlg.Title = "Open File"
Private fdlg.InitialDirectory = "E:\"
Private fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
Private fdlg.FilterIndex = 2
Private fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = DialogResult.OK Then
textBox1.Text = fdlg.FileName
End If

Title member let you set the title of the open dialog.
Filter member let you set a filter for types of files to open.
FileName member gives you the name of the selected file.

Monday, October 19, 2009

Getting Rid of the "Access denied for user ..." Error in PHP

This error usually looks like this :
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\intra\process_mypage.php on line 382

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\intra\process_mypage.php on line 382

To get rid of this error, follow this step :
  • Check your connection to the database
  • Check server name, username and password
  • Check whether the connection is opened or not, because the common mistake is that you forgot to open the connection :p