Click to See Complete Forum and Search --> : Why won't this work??


SoniaE
May 29th, 2003, 12:43 PM
HI,
I'm trying to do an insert into a SQL Server 2000 database. My qry string looks like this:
INSERT INTO ermdLocationTemperature(Location, [Date], Temperature)
Values(1, '5/5/2005 10:41:45 AM', 245.1245)

I pass the string into the sub below. Whenever I try and do line
myCommand.ExecuteNonQuery(), I get an error. I ran the qry in Query analyzer and it runs fine/performs the insert. What am I missing? The exact error is:
The statement has been terminated.
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

Private Sub WriteToDatabase(ByVal command As String)
Dim sqlConn As SqlConnection = New SqlConnection(DatabaseKey)
Dim myCommand As New SqlCommand(command, sqlConn)

myCommand.Connection.Open()
Try
myCommand.ExecuteNonQuery()
Catch e As Exception
Console.Write(e)
End Try
myCommand.Connection.Close()

myCommand.Dispose()
myCommand = Nothing
End Sub

Private Sub PerformWrite(ByVal intLocation As Integer, _
ByVal dtTemperatureDate As Date, ByVal decTemperature As Decimal)
Dim strQry As String 'Holds Insert Statement

get_DatabaseKey() 'Get the connection String

'Build Insert Statement
strQry = "INSERT INTO ermdLocationTemperature(Location, [Date], Temperature)" _
& " Values(" & intLocation & ", '" & dtTemperatureDate & "', " & decTemperature & ")"

WriteToDatabase(strQry) 'Perform the write into the database
End Sub

SoniaE
May 29th, 2003, 01:44 PM
Connecting to the wrong database...Man I'm glad its Thursday!! I hit the stupid tree today