Q:

Giving Database path from textbox

I want to create new MS Access  Database by Giving path from Textbox instead of prewritten path on Runtime in vb.  net
Imports ADOX
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Try
        Dim cat As Catalog = New Catalog()

        cat. Create("Provider=Microsoft. Jet. OLEDB.4.0;" & _
                    "Data Source=C:\Users\Anish Choudhary\Desktop\New folder\N.mdb;" & _
                    "Jet OLEDB:Engine Type=5")

        MessageBox. Show("Database Created Successfully")

        cat = Nothing

    Catch ex As Exception
        MessageBox. Show("Database already Exists")
    End Try
End Sub

End Class

A:

Instead of using a textbox to get a folder path use the appropriate control provided by the NET Library.  It is called FolderBrowserDialog
TextBoxes are not very good for this kind of operation.  The user could have a lot of problems typing a correct path, instead a FolderBrowserDialog in its simplicity allows to reach the correct path without manually typing anything
Dim fbd = New FolderBrowserDialog()
fbd. Description = "Select a folder for the new database"
fbd. RootFolder = Environment. SpecialFolder. MyComputer
fbd. ShowNewFolderButton = True
If fbd. ShowDialog() = DialogResult. OK Then
    Try
        Dim filePath =  Path. Combine(fbd. SelectedPath, "N.mdb")
        Dim cat As Catalog = New Catalog()
        cat. Create("Provider=Microsoft. Jet. OLEDB.4.0;" & _
                    "Data Source=" & filePath & _
                    "Jet OLEDB:Engine Type=5")
        MessageBox. Show("Database Created Successfully")
        cat = Nothing
    Catch ex As Exception
        MessageBox. Show("Database already Exists")
    End Try
End If

