DB and :Net questions

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 1
Reputation: Xelloss is an unknown quantity at this point 
Solved Threads: 0
Xelloss Xelloss is offline Offline
Newbie Poster

DB and :Net questions

 
0
  #1
Nov 26th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: DB and :Net questions

 
0
  #2
Nov 26th, 2006
>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?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: sierrasoft is an unknown quantity at this point 
Solved Threads: 0
sierrasoft sierrasoft is offline Offline
Light Poster

Re: DB and :Net questions

 
0
  #3
Nov 30th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 1
Reputation: Anirudha is an unknown quantity at this point 
Solved Threads: 0
Anirudha Anirudha is offline Offline
Newbie Poster

Re: DB and :Net questions

 
0
  #4
Nov 30th, 2006
Originally Posted by Xelloss View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC