First of I am not engllish speaker so if something its off forgive me please.

Now on the topic, I have not touch VB in 4 or years and now changing from VB6 to VB 2005

Now I used to work with dataset on VB6 but the teacher is really.... patetic to said at best, and its making us use something like this.

conexion = "provider = microsoft.jet.oledb.4.0;data source= C:\Download\Anime.mdb"
Dim con As New System.Data.OleDb.OleDbConnection(conexion)
Dim adaptador As System.Data.OleDb.OleDbDataReader
consulta = "select Nombre, Tipo, Discos, Completa from CD where Nombre like '" + TextBox2.Text + "' "
Dim comando As New System.Data.OleDb.OleDbCommand(consulta, con)
con.Open()
adaptador = comando.ExecuteReader
While adaptador.Read
TextBox15.Text = (adaptador.Item(0))
TextBox14.Text = (adaptador.Item(1))
TextBox13.Text = (adaptador.Item(2))
RadioButton2.Checked = (adaptador.Item(3))
End While
adaptador.Close()
con.Close()

So far I have been able to read of database but I want to introduce things (currently working on this), delete and edit. Sadly for the moment I am short on time to finish this and other projects so a bit forced to ask for help.

Bedsides this I have 3 questions.

1.- is there a way to avoid typing all that each time I want to acces the database (example each button), and if so how.

2.- is there a better way to manipulate the database.

3.- oh yeah, in 1 I am taking a "type" of cd from another database, but instead of vb using the text to search for it, its using the value.
example db1. "type" "id" db2 "type" "name"... etc

In vb its taking the name from a combo box, but the datase its asking me from the id.

I know its to much bother even if its little the help or a link to somewhere it would help me a ton.

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

>is there a way to avoid typing all that each time I want to acces the database (example each button), and if so how.


Copy 'n' paste ;)

> is there a better way to manipulate the database.

If it works don't worry about it.

>oh yeah, in 1 I am taking a "type" of cd from another database, but instead of vb using the text to search for it, its using the value.
example db1. "type" "id" db2 "type" "name"... etc

So have you created a relevant class?

1.- is there a way to avoid typing all that each time I want to acces the database (example each button), and if so how.

Ans: Declare the con, comando in the General Declarations section.
Set the Connection string and command text (con) in the Form_Load event instead of each button.

General Declarations:

Dim con As System.Data.OleDb.OleDbConnection
Dim comando As System.Data.OleDb.OleDbCommand
Dim adaptador As System.Data.OleDb.OleDbDataReader

Form_Load:
conexion = "provider = microsoft.jet.oledb.4.0;data source= C:\Download\Anime.mdb"
consulta = "select Nombre, Tipo, Discos, Completa from CD where Nombre like '" + TextBox2.Text + "'

con= New System.Data.OleDb.OleDbConnection (connexion)
comando= New System.Data.OleDb.OleDbCommand (consulta,con)

The rest of the code goes in the button for retrieving data.

2.- is there a better way to manipulate the database.
Ans: You can use a DataAdaptor and DataSet

3. Need more Explanation

First of I am not engllish speaker so if something its off forgive me please.

Now on the topic, I have not touch VB in 4 or years and now changing from VB6 to VB 2005

Now I used to work with dataset on VB6 but the teacher is really.... patetic to said at best, and its making us use something like this.

conexion = "provider = microsoft.jet.oledb.4.0;data source= C:\Download\Anime.mdb"
Dim con As New System.Data.OleDb.OleDbConnection(conexion)
Dim adaptador As System.Data.OleDb.OleDbDataReader
consulta = "select Nombre, Tipo, Discos, Completa from CD where Nombre like '" + TextBox2.Text + "' "
Dim comando As New System.Data.OleDb.OleDbCommand(consulta, con)
con.Open()
adaptador = comando.ExecuteReader
While adaptador.Read
TextBox15.Text = (adaptador.Item(0))
TextBox14.Text = (adaptador.Item(1))
TextBox13.Text = (adaptador.Item(2))
RadioButton2.Checked = (adaptador.Item(3))
End While
adaptador.Close()
con.Close()

So far I have been able to read of database but I want to introduce things (currently working on this), delete and edit. Sadly for the moment I am short on time to finish this and other projects so a bit forced to ask for help.

Bedsides this I have 3 questions.

1.- is there a way to avoid typing all that each time I want to acces the database (example each button), and if so how.

2.- is there a better way to manipulate the database.

3.- oh yeah, in 1 I am taking a "type" of cd from another database, but instead of vb using the text to search for it, its using the value.
example db1. "type" "id" db2 "type" "name"... etc

In vb its taking the name from a combo box, but the datase its asking me from the id.

I know its to much bother even if its little the help or a link to somewhere it would help me a ton.

Hello,
if u want to run the Delete insert or update type queries then use the following code
1. make a connection string . as u make "conexion"
2. write code

dim cmd as new oledbcommand("Insert Query",conexion)
conexion.open()
cmd.executeNonQuery()
conexion.close()

Try this code it may run

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.