PC Review


Reply
Thread Tools Rate Thread

Converting code ADO VBA to ADO net VB.net

 
 
Gum
Guest
Posts: n/a
 
      19th Aug 2009
I wish to access sql data in a vb net (vs2008) program and have an ADO VBA
(in excel) routine that was used to read the files in excel. The code (in
excel VBA) is:

Sub PriceExtract()
' Create a connection object.
Dim cnLevel As ADODB.Connection
Set cnLevel = New ADODB.Connection
' Provide the connection string.
Dim strConn As String

'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"

'Connect to the Pubs database on the local server.
strConn = strConn & "DATA SOURCE=mydata;INITIAL
CATALOG=myCat;Trusted_Connection=Yes"

'Now open the connection.
cnLevel.Open strConn
' Create a recordset object.
Dim rsLevel As ADODB.Recordset
Set rsLevel = New ADODB.Recordset

With rsLevel
' Assign the Connection object.
.ActiveConnection = cnLevel
' Extract the required records.
.Open "SELECT * FROM vw_HighPrice"
' Copy the records into cell A1 on Sheet1.
Sheet1.Range("A1").CopyFromRecordset rsLevel

' Tidy up
.Close
.Open "SELECT * FROM vw_MidPrice"
' Copy the records into cell A2 on Sheet1.
Sheet1.Range("A2").CopyFromRecordset rsLevel

' Tidy up
.Close
.Open "SELECT * FROM vw_LowPrice"
' Copy the records into cell A3 on Sheet1.
Sheet1.Range("A3").CopyFromRecordset rsLevel


' Tidy up
.Close
End With

cnLevel.Close
Set rsLevel = Nothing
Set cnLevel = Nothing
End Sub

The code reads lines from the sql view files and excel parses it into say 4
data fields. The code works well in Excel. I wish to access the same data
within the vb net project.

The data in the sql is constantly updated and repeatedly needs to be
accessed by the VB net project.




 
Reply With Quote
 
 
 
 
Gum
Guest
Posts: n/a
 
      19th Aug 2009
To Mark Rae [MVP]: No Thanks for 'let me google that for you'. Been there
done that.

I found the answer in one of Bill Vaughn's books.


"Mark Rae [MVP]" wrote:

> "Gum" <(E-Mail Removed)> wrote in message
> news:1D328689-AEEE-4C2D-AAFA-(E-Mail Removed)...
>
> > The code reads lines from the SQL view [files] and Excel parses it into
> > say 4
> > data fields. The code works well in Excel. I wish to access the same
> > data
> > within the VB.NET project.

>
> http://www.lmgtfy.com/?q=%22VB.NET%2...2SQL+Server%22
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      19th Aug 2009
You wanted the "Oh, let me rewrite your application for you." response?

If you've been there and done that [correctly], you wouldn't have needed to
post your question.

-Scott


"Gum" <(E-Mail Removed)> wrote in message
news:34F35C65-1B14-45F4-B1A1-(E-Mail Removed)...
> To Mark Rae [MVP]: No Thanks for 'let me google that for you'. Been
> there
> done that.
>
> I found the answer in one of Bill Vaughn's books.
>
>
> "Mark Rae [MVP]" wrote:
>
>> "Gum" <(E-Mail Removed)> wrote in message
>> news:1D328689-AEEE-4C2D-AAFA-(E-Mail Removed)...
>>
>> > The code reads lines from the SQL view [files] and Excel parses it into
>> > say 4
>> > data fields. The code works well in Excel. I wish to access the same
>> > data
>> > within the VB.NET project.

>>
>> http://www.lmgtfy.com/?q=%22VB.NET%2...2SQL+Server%22
>>
>>
>> --
>> Mark Rae
>> ASP.NET MVP
>> http://www.markrae.net
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Needs help converting some pseudo code into VB code williameis Microsoft Excel Programming 2 21st Dec 2006 07:46 PM
Help converting C# code to VB =?Utf-8?B?UGhpbGw=?= Microsoft VB .NET 4 22nd Jun 2006 07:14 PM
Converting vb code to C# Stephen Microsoft C# .NET 1 18th Jan 2005 01:29 PM
Help converting this code from vb6 to vb.net? Steve Microsoft VB .NET 11 22nd Jan 2004 10:14 AM
help converting code from C to C# Mountain Bikn' Guy Microsoft C# .NET 2 12th Dec 2003 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 AM.