|
-
Aug 24th, 2001, 10:34 AM
#1
Thread Starter
Hyperactive Member
Accessing Data
When I used VB6 I would explicitly access SQL servers in that I did not use the data environment, rather I would use code like:
Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
With cn
.Provider = "SQLOLEDB"
.ConnectionString = "Data Source=SQLServer;Initial Catalog=MyCat"
.Open
End With
rs.Open "SELECT * FROM Table1"
Text1.Text = rs!Field
I am just wondering if this is the best way to do this in ADO.NET.
Thanks!!
-
Aug 25th, 2001, 05:08 AM
#2
You should use the classes found in the System.Data.ADO namespace.
-
Sep 13th, 2001, 07:55 AM
#3
New Member
could you post some code as an example?
-
Sep 13th, 2001, 10:40 AM
#4
The code are the same as in VB6 it's just that you have to set a reference to the System.Data and you should also include the namespace System.Data.ADO
Best regards
-
Sep 14th, 2001, 02:11 AM
#5
New Member
hmmm I don't mean to sound rude but I don't think thats the case.
I've tried using vb6 ado in .Net and it does'nt work. (which worked perfectly in vb6)
out of all the things changed in .Net, Database Access is one of the biggest.
-
Sep 14th, 2001, 03:37 AM
#6
Of course it's a big change in how .Net handles ADO internally.
But the method names and properties are practically the same.
If you have a look in the .Net framework about the System.Data.ADO namespace you'll see that the changes you have to make is minor.
-
Sep 14th, 2001, 03:53 AM
#7
I'm sorry!
Now that I've had a closer look I see that I was looking at some code I made in beta1.
You could use the ADODB interoperability assembly.
Simply set a reference to that library and try the code. It works perfectly for me.
VB Code:
Imports ADODB
Public Class Form1
Inherits System.Windows.Forms.Form
Private cn As New Connection()
Private rs As New Recordset()
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
'auto generated code removed in this example
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With cn
.Provider = "SQLOLEDB"
.ConnectionString = "Data Source=SomeSQLServer;Initial Catalog=Anything"
.Open()
End With
rs.Open("Select * from tblFirst", cn)
TextBox1.Text = rs("MyField").Value
End Sub
End Class
Best regards
-
Sep 14th, 2001, 07:37 AM
#8
New Member
ok thanks
I have another question about ado.net.
how do you use variables in sql query's ?
for example i used this code in a username/password protected program i did in vb6
Code:
strUser = txtUser.Text
strPass = txtPass.Text
sqlUser = "SELECT * FROM tblUserPass WHERE tblUserPass.Username = '" & strUser & "'" & " AND tblUserPass.Password = '" & strPass & "'"
Set rsUserPass = dbUserPass.Execute(sqlUser)
If rsUserPass.BOF = True And rsUserPass.EOF = True Then
Denied()
Else
Granted()
End If
how would I do that in .Net ?
Thankyou.
-
Sep 15th, 2001, 12:20 AM
#9
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|