hello every1
actually m new to vb.net,
i have installed oracle 9i on my system and i dont knw how to connect even a simple form to my sql table in which i have two fields named first_name and last_name, the name of the table in sql is user.
can some1 please tell me how to connect my form1 with the my sql table so that when i type the names in two text boxes the data is stored in the database.........
ALSO HOW TO CONFIGURE THE DATABASE I.E
CONTROL PANEL-->ADMINISTRATIVE TOOLS-->ADD CONNECTION......
IS THERE ANY NEED OF DOING IT.......
THANX IN ADVANCE....

Dani AI

Generated

There’s a mismatch in the original post: says Oracle 9i is installed while the thread tags say MySQL. Those are different DBMSs and require different providers and connection strings. ODBC (what suggested) will work for either, but using the vendor’s ADO.NET provider is usually simpler (MySQL’s Connector/NET for MySQL; ODP.NET or Oracle’s managed provider for Oracle). Visual Studio’s “Add Connection” / an ODBC DSN is optional—useful for testing or DSN-based apps, but not required when using a DSN-less connection string.

Quick checklist before wiring the form:

  • Confirm the database server/listener is running and reachable (host, port, credentials).
  • Install the correct provider and add the assembly (or NuGet package) to the project.
  • Avoid reserved names: a table named user is problematic — rename to users or quote it.
  • Test the connection in Server Explorer or with a tiny console app first.
  • Always use parameterized queries and proper disposal of connections.

Example (MySQL pattern — different provider needed for Oracle):

Imports MySql.Data.MySqlClient

Dim cs = "Server=localhost;Database=yourdb;Uid=dbuser;Pwd=secret;"
Using cn As New MySqlConnection(cs)
    cn.Open()
    Using cmd As New MySqlCommand("INSERT INTO `user` (first_name, last_name) VALUES (@fn, @ln)", cn)
        cmd.Parameters.AddWithValue("@fn", TextBox1.Text)
        cmd.Parameters.AddWithValue("@ln", TextBox2.Text)
        cmd.ExecuteNonQuery()
    End Using
End Using

If an OdbcException appears on Open (the error reported), inspect the exception message/details: common causes are wrong connection string, missing driver/DSN, closed listener, firewall, or wrong TNS alias for Oracle. Wrap Open in a try/catch to capture the full message and error code. ’s question about Imports is answered by noting that import/using directives only shorten type names; they don’t affect the runtime connection.

Recommended Answers

All 5 Replies

First of all if you want to make a connection between VB.net and a database using oracle you have to to the following

Imports System.Data.Odbc

at the top of the form code file.

then add 2 variables for the ODBC connection and command

dim Mycon As New odbcConnection
    dim Mycmd As New odbcCommand

Next what I prefer is making a new procedure containing the connection string and the connection between the command object and the connection.

Sub OpenConnection()
        Mycon.ConnectionString = "data source= ;initial catalog=;user id=;password="
        Mycon.Open()
        Mycmd.Connection = Mycon
    End Sub

then in the FormLoad event, add OpenConnection()

Now you've successfully connected to the database, do a research on how to execute queries using textboxes, buttons, etc...

Sounds like a noob but I'm still a beginner too.

Member Avatar for Member #857553

Why do you add the Imports System.Data.Odbc at the top of the form code file. Just curious. I'm a bit of a noob too.

Is there any need to add data sources from the toolbox as well?

DANTHEVAM, It is giving an error on mycon.open,
it says:An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in system.data.dll

Additional information: System error.

Why do you add the Imports System.Data.Odbc at the top of the form code file. Just curious. I'm a bit of a noob too.

just because when he declares the variables, he doesn't have to call it dim mycon as new system.data.odbc.odbcconnection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.