Home » SQL & PL/SQL » SQL & PL/SQL » SQL with Visual Basic 06
SQL with Visual Basic 06 [message #10702] Wed, 11 February 2004 00:31 Go to next message
Thato
Messages: 8
Registered: January 2004
Junior Member
Hi! Guys

Can someone please show me how to write and execute SQL within Visual Basics. e.g If I want to accept an employee number from the User then display His name on a textbox.
Re: SQL with Visual Basic 06 [message #10703 is a reply to message #10702] Wed, 11 February 2004 01:19 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Link

MHE
Re: SQL with Visual Basic 06 [message #10704 is a reply to message #10703] Wed, 11 February 2004 01:30 Go to previous messageGo to next message
Rishi
Messages: 63
Registered: January 2001
Member
1. Open a new Project in VB.

2. Go to Project > More Active x Designers > Data Environment.

3. Close the Data Environment Window

(or the Other way you can
use the Data Environment windows for using connection1
to connect to your SQL or Oracle Server.)

( We will assume that v r using SQL Server 2000 here.)

4. Next on the form Load event write the following code.

Private Sub Form_Load()
Dim cn As New ADODB.Connection

cn.Open ("Provider=SQLOLEDB.1;Password='yourpassword_for_database or operating system';
Persist Security Info=True;User ID='youruser_for_database';Initial Catalog= 'YourDataBaseName';
Data Source='Your Server Name'")

' These obove 3 lines should be in a single line in VB

' (" This cn or connection can be created through Data Environment window
' also by configuring connection as mentioned earlier")

Dim rs As New ADODB.Recordset
rs.Open ("select name from yourtable"), cn, adOpenKeyset, adLockPessimistic

' ("Assuming that yourtable contains a single row")

Dim nm As String
nm = rs(0)
txtone.Text = nm

' (" Where txtone is the name of your text box on form1 ")

rs.Close

End Sub


5. Now run your project.

The only difficulty that yau can find in this is how to connect to
your Database Server. Either use 32-bit ODBC or code manually as shown
above.

I am sure that if u can do this then u can also input
a emp no and display its name in a text box .

Regards
Rishi
Re: SQL with Visual Basic 06 [message #11153 is a reply to message #10704] Tue, 09 March 2004 17:16 Go to previous message
m.suhandi
Messages: 1
Registered: March 2004
Junior Member
koding untuk save apasih
Previous Topic: About primary keys
Next Topic: SQL Tuning
Goto Forum:
  


Current Time: Thu Apr 25 21:29:35 CDT 2024