Hi all,
I have the following procedure that connects to my database.
Sub getDateModified()
Dim fileCreatedDate As DateTime = File.GetCreationTime(strFilePath + "\CPI1.csv")
Dim stmt As String
SQLConn.ConnectionString = ConnString
SQLConn.Open()
stmt = "select Table_Numbers From tblRelease_Dates Where (Release_Date Between '" + fileCreatedDate + "' And GETDATE())"
SQLCmd.Connection = SQLConn
SQLCmd.CommandText = stmt
SQLdr2 = SQLCmd.ExecuteReader
If SQLdr2.HasRows Then
While SQLdr2.Read()
dtRd = SQLdr2.GetSqlInt32(0)
End While
End If
SQLdr2.Close()
SQLConn.Close()
SQLConn.ConnectionString = ConnString
SQLConn.Open()
stmt = ""
stmt = "select DATEPART('m',Reference_Period) from tblRelease_Dates where (Release_Date between '" + fileCreatedDate + "' and GETDATE())"
SQLCmd.CommandText = stmt
SQLdr2 = SQLCmd.ExecuteReader
If SQLdr2.HasRows Then
While SQLdr2.Read()
eDt = SQLdr2.GetSqlDateTime(0)
End While
End If
SQLConn.Close()
End Sub
This works up until second instance of:
SQLdr2 = SQLCmd.ExecuteReader
Once it hits this line I get the error: "Invalid parameter 1 specified for datepart" which leads me back to this line:
stmt = "select DATEPART('m',Reference_Period) from tblRelease_Dates where (Release_Date between '" + fileCreatedDate + "' and GETDATE())"
What I am trying to attempt is getting the month number from the date variable called Reference_Period, which is of the type [DT_DBDATE]. I've tried passing this datepart into an integer type and a string type and both ways give me problems so my problem must be the actual DATEPART function.
I really need the month number for the rest of my code to work, can anyone show me the right way?