Click here to Skip to main content
14,738,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying with the below code to retrieve data from sql server database and display it in excel sheet. But its not working fine.

Getting exception as "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another" in the expression,con).

Below is the code which I used,
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim con As New SqlConnection(WebConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString)
Dim SQL = "select username,password,id from tbl_Login_Details "
Dim Recordset = Server.CreateObject("ADODB.Recordset")


'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
'Transfer the data to Excel
'Save the Workbook and Quit Excel
'Close the connection
End Sub
Updated 15-Mar-11 0:17am
Sandeep Mewara 15-Mar-11 5:13am
Next time onward use PRE tags to format code part. It makes your question readable.

1 solution

Have a sample on how to create a connection and recordset in ADO here:[^][^]

BTW, based on similar issues faced and resoled suggests the object type to be strongly declared, look here:
Similar discussion[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900