Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / July 2007



Tip: Looking for answers? Try searching our database.

how to wirte to Ms Excel in VB by retrieve data from SQL Server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
carmen413 - 27 Jul 2007 08:21 GMT
Dear All,

how to write the to Ms Excel File by retireve data from SQL Server.

below src code i use:

Public Sub Write2Excel()
Dim db_connect
Path = "C:\Book1.xls"
   Set db_connect = New ADODB.Connection
    Dim rse As New ADODB.Recordset
   Dim rs As New ADODB.Recordset
   
   db_connect.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Path &
"; Extended Properties=Excel 8.0;"
   'db_connect2.Open "PROVIDER=SQLOLEDB;Data Source=GHSERP;Initial
Catalog=GHS;User ID=sa;Password=admin123"
 
    SQL = "Select OrderNo From [Sheet1$]"
   
    Set rse = db_connect.Execute(SQL)
    rs.Open ("select * from ExportDetail"), sqldb
'sqldb is PROVIDER=SQLOLEDB;Data Source=OSTRIO10;Initial
Catalog=BUsinessUnit;User ID=sa;Password=admin;
    Do While Not rs.EOF
    With rse
    .AddNew
    .Fields(0) = rs.Fields(0)
    .Update
    End With
    rs.MoveNext
    Loop

    'SQL = "Insert Into Shet1$(OrderNo) values('" & rs.Fields(0) & "')"
   'db_connect.Execute (SQL)
    MsgBox "finish"

End Sub

run-time error '3251':

Current Recordset does not support updating. This may be a limitation of the
provider, or or the selected locktype.

Kindly advice

thank you

best regards,
Carmen
DK - 27 Jul 2007 20:00 GMT
> Dear All,
>
[quoted text clipped - 49 lines]
> --
> Message posted via VBMonster.comhttp://www.vbmonster.com/Uwe/Forums.aspx/db-access/200707/1

What type of data do you have in that column? If you have a mix of
numeric and character data then you will get this error and you will
have to resort to using automation to manage this spread sheet.
DK - 27 Jul 2007 20:05 GMT
> > Dear All,
>
[quoted text clipped - 55 lines]
>
> - Show quoted text -

You also need to add ;HDR=Yes; to your connection string.

    db_connect.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
& Path & _
      "; Extended Properties=""Excel 8.0;HDR=Yes;"""
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.