I am trying to fetch data from SQL Server using a text file as input, but I'm getting an error:
Arithmetic overflow error converting varchar to data type numeric
Please let me know if the below code is wrong or anything else needs to be added:
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
Dim iCols As Integer
Dim X As Double
Dim TXT As String
Dim Y As String
Dim A As Double
strcon = "Provider=SQLOLEDB;Data Source=SERVER1;Initial Catalog=MYDB;Integrated Security=SSPI;"
cnn.Open strcon
cnn.CommandTimeout = 900
Open "C:\Users\Gaurav.Shrivastava\Desktop\SLIp\New folder\TESTING.txt" For Input As 1
X = 0
Do While Not EOF(1)
Line Input #1, TXT
Y = Val(TXT)
A = Y
StrQuery = "Select * from FRA_RETAIL where COM_A_NO=" & A & ""
rst.Open StrQuery, cnn
X = X + 1
Loop
For iCols = 0 To rst.Fields.Count - 1
Worksheets("Sheet1").Cells(1, iCols + 1).Value = rst.Fields(iCols).Name
Next
Sheets(1).Range("A2").CopyFromRecordset rst
'rst.Close
'cnn.Close
'Set rst = Nothing
'ActiveWorkbook.Close SaveChanges:=True
'Application.Quit
'Application.ActiveWindow.Close
where COM_A_NO=" & A & ""cause the string value ofAcan't be converted tonumeric