I'm trying to figure out this error message and I'm not sure what exactly is the issue.
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
tmpsql = "select EVE_GID from Events where EVE_DATED = '" & request("EVE_DATED") & "' and
EVE_STARTTIME = '" & request("EVE_DATED") & " " & request("EVE_STARTTIME") & "'"
rs.Open tmpsql,MM_editConnection
I think it has to do with my quotes but I'm not sure. Can anyone give me a clue on why I keep getting this error message? The data is hosted on a SQL server.
O yes
EVE_GID = int EVE_DATED = datetime EVE_STARTTIME = datetime
Spit out your SQL statement before you execute it an see what you're getting:
tmpsql = "select EVE_GID from Events where EVE_DATED = '" & request("EVE_DATED") & "' and
EVE_STARTTIME = '" & request("EVE_DATED") & " " & request("EVE_STARTTIME") & "'"
response.write(tmpsql)
'rs.Open tmpsql,MM_editConnection <-- comment out this
Related
Dim nilx As String = textbox1.text --> (example. data like this. "10001,010001")
Using koneksi As New SqlConnection(stringkoneksi)
koneksi.Open()
Dim perintah As SqlCommand = koneksi.CreateCommand
perintah.CommandText = "update mytabledata set rumus='" & TextBox2.Text & "'
where code in (" & nilx & ") "
perintah.CommandType = CommandType.Text
perintah.ExecuteNonQuery()
koneksi.Close()
error when execute
Conversion failed when converting the nvarchar value '123test' to data type int
because in mytabledata there is code 123test, if i delete code 123test running well
so how to update data where code in (" & nilx & ")
error when execute
Conversion failed when converting the nvarchar value '123test' to data type int
because in mytabledata have code 123test, if i delete code 123test running well
so how to update data where code in (" & nilx & ")
if i have data nilx = "10001,010001,9912AA,1123BC"
Your codes in nilx must be in single quotes:
"'10001','010001','9912AA','1123BC'"
Also, use parameterized queries SQL Injection And Parameterized Queries. Don't just concatenate TextBox2.Text in your commands.
I am trying to do an update on a table in SQL Server 2008 R2, but the column writes only 8000 characters.
The column's datatype is set to text, but I have already tried to change to varchar(max) with no success.
I also used the cast('variable' as text) and cast('variable' as varchar(max)), also unsuccessfully.
When doing the same update by the SQL console (I made a response.write on the screen, copied and pasted it) or inserted more than 8000 characters manually, it works (through Microsoft Visual Studio).
sql_Up = "UPDATE ABVC_Eventos SET titulo_eve = '" & Strip(Evento) & "', cod_sup_eve = '" & Strip(cod_sup_eve) & "', cod_sup2_eve = '" & Strip(cod_sup2_eve) & "', texto_eve = CAST('" & Strip(texto_eve) & "' AS TEXT), WHERE id_eve = '" & Strip(Cod_Evento) & "'"
set Rs_sqlUp = bco.Execute(sql_Up)
The 'Strip' function is for sanitization.
Private Sub cmdAdd_Click()
'add data to table
CurrentDb.Execute "INSERT INTO Products(ProductCode, ProductName, Category, UnitPrice, UnitCost, QuantityInStock, SupplierCode) " & _
" VALUES (" & Me.txtProductCode & " , '" & Me.txtProductName & "' , '" & Me.cboCategory & "' , '" & Me.txtUnitPrice & "' , '" & Me.txtUnitCost & "' , '" & Me.txtQuantityInStock & "' , '" & Me.cboSupplierCode & "')"
'refresh data on list of form
ProductsSub.Form.Requery
End Sub
the code above is suppose to record the data that has been input from the interface, but it does not do anything. The same format of code was used in a different form and it worked. Really weird, but i don't how it was possible.
You'll need to debug this. One of the values you are referencing visa the Me object is not resolving. Place a breakpoint on the CurrentDB.Execute command, and hover over each Me reference (i.e. Me.txtProductCode) to make sure it is obtaining the correct value for the insert. If you have moved this to a library, you may want to use CodeDB.Execute instead of CurrentDB.Execute. I would also check the table to see if the actual INSERT is working as there may be an issue with the Requery event.
I have a web app with a form that I am trying to pass to an ASP.NET server (using VB.NET) and then on to a MS SQL Server table. The form uses a jQuery datepicker in several textboxes and formats them as MM/dd/yyyy. The form fields are then passed through a PageMethod to the web server which takes the various field values and combines them into a SQL UPDATE command.
I am constantly getting the following error whenever I try to execute the SQL command:
Conversion failed when converting date and/or time from character string.
Here is the code on the server:
Using myConn As New System.Data.SqlClient.SqlConnection(CString.ConnectionString)
myConn.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand("UPDATE table " & _
"SET type = '" & type & "', " & _
"target = '" & "#target" & "', " & _
"patient = '" & patient & "', " & _
"dob = '" & "#dob" & "' " & _
"WHERE serial = '" & serial & "'", myConn)
cmd.Parameters.Add(SqlParameter("#target", Data.SqlDbType.Date))
cmd.Parameters.Add(SqlParameter("#dob", Data.SqlDbType.Date))
If target = "" Then
cmd.Parameters("#target").Value = Data.SqlTypes.SqlDateTime.Null
Else
cmd.Parameters("#target").Value = target
End If
If dob = "" Then
cmd.Parameters("#dob").Value = Data.SqlTypes.SqlDateTime.Null
Else
cmd.Parameters("#dob").Value = dob
End If
cmd.ExecuteNonQuery()
End Using
Note: I've tried about twenty different ways of parsing the dates, converting them to dates, changing around the formats and none of it has worked.
Note 2: The conditional statements at the end are simply to prevent empty date fields from being stored in the SQL DB as "1/1/1900", but rather as an actual SQL NULL value. From debugging though, it seems that this is not the issue - it is when there is an actual value that the error is fired.
If anyone can see what I'm doing wrong and how I might fix it, it would be greatly appreciated. Thanks in advance for your help!
You are mixing up your parameterized and non-parameterized parts (why aren't you parameterizing everything?)
Dim cmd As New System.Data.SqlClient.SqlCommand("UPDATE table " & _
"SET type = '" & type & "', " & _
"target = #target, " & _
"patient = '" & patient & "', " & _
"dob = #dob " & _
"WHERE serial = '" & serial & "'", myConn)
Are you including time? DateTime fields require date and time.
I am trying to maintain a log field (fldUserLog ) of my database table so that when updating each raw, the log field will be amended with given log string.
Log string
strUserLog = "Added by : " & Session("auth_Id") & " at " & Now() & " from IP " &
Request.ServerVariables("REMOTE_ADDR") & vbCrLf
and I am using SQL command parameters to UPDATE query. as follows
strSQLQuery = "UPDATE myTable SET " _
& "fldTitle = #xTitle, " _
& "fldDesc = #xDesc, " _
& "fldUserLog = fldUserLog + #xUserLog " _
& "WHERE fldId = #xId ;"
strMessage = "updated"
ObjAddDB.setCommand(strSQLQuery)
With ObjAddDB
.setParameters("#xTitle", frmTitle.Text)
.setParameters("#xDesc", frmDesc.Text)
.setParameters("#xUserLog", strUserLog)
.setParameters("#xId", MyItemId)
End With
Please note that setCommand and setParameters are my own methods I am using in my database.vb class file.
I get following error when its executed
Exception Details:
System.Data.SqlClient.SqlException:
Incorrect syntax near 'fldUserLog'.
please help me to use my UPDATE query to amend existing data with command parameters.
If the format of the fldUserLog field value contains spaces, you need to embrace the value with [ ] ..
& "fldUserLog = [fldUserLog #xUserLog] " _
I guess what you may want to write is the following:
& "fldUserLog = #xUserLog " _