I am trying to validate data, and depends on the result checked or unchecked the related check box, but getting below error?
Microsoft VBScript compilation error '800a03ee'
Expected ')'
<%# Language=VBScript %>
<%
Function Select()
Dim apple, banana, true
Dim SQL
SQL = " SELECT code, name, value FROM fruits WHERE code = '" &("myCode")& "'"
If (SQL = SQL & "name <> '" banana "' AND value <> '" true "' ") or (SQL = SQL & "name = '" banana "' AND value <> '" true "' ") Then
checkedBox.Common.Name = "chkbanana"
checkedBox.Checked = false
Else
checkedBox.Common.Name = "chkbanana"
checkedBox.Checked = true
End If
If (SQL = SQL & "name <> '" apple "' AND value <> '" true "' ") or (SQL = SQL & "name = '" apple "' AND value <> '" true "' ") Then
checkedBox.Common.Name = "chkapple"
checkedBox.Checked = false
Else
checkedBox.Common.Name = "chkapple"
checkedBox.Checked = true
End If
End Function
%>
You have a lot of syntax errors. When concatenating strings you need to use & around banana and such. Also, the logic seems off as you are comparing something with itself and concatenating, basically you can get it to compile and never have it run any of your conditionals as the else statements will always be run. You may want to use contains or some other comparison.
But for syntax your first if statement should look like this:
If (SQL = SQL & "name <> '" & banana & "' AND value <> '" & true & "' ") Or (SQL = SQL & "name = '" & banana & "' AND value <> '" & true & "' ") Then
Also you should not use true as the name of a variable.
Related
I have two recordset which want to update one of them by value of the other. I did like this
stSql = "SELECT dbo.tblCableProperty.CatalogCode FROM dbo.tblCable INNER JOIN " & _
" dbo.tblCableProperty ON dbo.tblCable.CablePcode = dbo.tblCableProperty.CablePcode" & _
" WHERE dbo.tblCable.prjsubcode=" & prjsubcode & " AND dbo.tblCable.Active=1 " & " And dbo.tblCable.Gtag='" & Gtag & "' And dbo.tblCable.TagNo=" & tagno & " And dbo.tblCable.NTag=" & NTag & " And dbo.tblCable.EndStr='" & EndStr & "'"
rs.Open stSql, cn, adOpenStatic, adLockOptimistic
catalogCode = rs!catalogCode
rs.Close
stSql = "SELECT *,'' as ShowNum FROM viwShowNum WHERE prjsubcode=" & prjsubcode & " AND Active=1 " & " And Gtag='" & Gtag & "' And TagNo=" & tagno & " And NTag=" & NTag & " And EndStr='" & EndStr & "' ORDER BY 8"
rs.Open stSql, cn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
stSql = "Select * from tblCoreCode where CatalogCode=" & catalogCode
Set rsCoreCode = New ADODB.Recordset
rsCoreCode.CursorLocation = adUseClient
rsCoreCode.Open stSql, cn, adOpenStatic, adLockOptimistic
While Not rs.EOF
criteria = "RealNum='" & rs!CoreNo & "'"
rsCoreCode.Filter = criteria
rs!ShowNum = CStr(rsCoreCode!ShowNum)
rsCoreCode.Filter = adFilterNone
rs.MoveNext
Wend
I get the following error on this part
rs!ShowNum = CStr(rsCoreCode!ShowNum)
multiple-step operation generated errors. check each status value
rsCoreCode!ShowNum is varchar(5). I tried to set the value
rs!ShowNum = "1"
but again I got the same error.
where is the problem?
Thank you
As asked in my comment, if rs.Updatable or rs!ShowNum.DataUpdatable are false, you can use this piece of code from Microsoft to retrieve an updatable RecordSet.
Same issue occurred to me the problem was that i violated an object property , in my case it was size the error came out as
"IntegrationException: Problem (Multiple-step operation generated errors. Check each status value.)"
Imports ADODB
Dim _RecordSet As Recordset
_rs.Fields.Append("Field_Name", DataTypeEnum.adVarChar, 50)
_Recordset("Field_Name").Value = _RecordDetails.Field_NameValue
_RecordDetails.Field_NameValue length was more than 50 chars , so this property was violated , hence the error occurred , so you should probably check if you didn't match one of the properties
Hi I am having a problem storing image to mssql server I tried both Memory stream and BLOB as well and in both scinarios I get the same error "cannot insert the value null into image column msg 515 level 16 state 2 line 1", any suggestion is more than welcome Thanks.
Dim sqlstring = " begin tran;"
sqlstring &= " INSERT INTO tbl_customers (stnname, cardnum,
family_name, city, fam_mem_nu, id_num, mrkz_num) VALUES
('" & stn & "','" & cd & "', '" & fmnm & "','" & ct & "', '"
& fnum & "', '" & idn & "', '" & cntr & "')"
sqlstring &= "INSERT INTO tbl_customers(imag) SELECT * FROM
OPENROWSET(BULK N'c:\temp\tempimg', SINGLE_BLOB) imag ; "
sqlstring &= "commit tran;"
sql.CommandText = sqlstring
sql.Connection = conn
conn.Open()
Dim ms As New MemoryStream
img = CameraControl1.SnapshotSourceImage
img.Save("c:\temp\tempimg", Imaging.ImageFormat.Png)
'CameraControl1.SnapshotSourceImage.Save(ms, Imaging.ImageFormat.Bmp)
' PictureBox3.Image.Save(ms, PictureBox3.Image.RawFormat)
' ms.ToArray()
' Dim data As Byte() = ms.GetBuffer()
' Dim p As New SqlClient.SqlParameter("#img", SqlDbType.VarBinary)
' p.Value = data
' sql.Parameters.Add(p)
Dim x As Integer = sql.ExecuteNonQuery
I am getting this specific error, help would be appreciated
Microsoft VBScript runtime error '800a01a8'
Object required: 'openRecordSet(...)'
/admin/users/affiliates/process.asp, line 47
Line 47 is Set objRecordset = openRecordset(strSQL, objConnection)
<%
SetUserLevel(" 2 ")
If (InStr(Request.ServerVariables("HTTP_REFERER"), "://jim/admin/users/affiliate") = 0) Then
Response.Redirect( "/admin/users/affiliate/" )
End If
Dim objConnection, objRecordset, strSQL, Affiliate_ID
If (IsEmpty(Request.Form("Affiliate_ID")) Or RTrim(Request.Form("Affiliate_ID")) = "") Then
Affiliate_ID = 0
Else
Affiliate_ID = prepareSQL(Request.Form("Affiliate_ID"))
End If
strSQL = "EXEC sp_User_Add_Affiliate " & _
Session("User_ID") & ", '" & _
prepareSQL(Request.Form("First_Name")) & "', '" & _
prepareSQL(Request.Form("Middle_Initial")) & "', '" & _
prepareSQL(Request.Form("Last_Name")) & "', '" & _
prepareSQL(Request.Form("Email_Address")) & "', '" & _
Request.ServerVariables("REMOTE_ADDR") & "', " & _
Session.SessionID & ", '" & _
prepareSQL(Request.Form("Address_1")) & "', '" & _
prepareSQL(Request.Form("Address_2")) & "', '" & _
prepareSQL(Request.Form("City")) & "', '" & _
prepareSQL(Request.Form("State")) & "', '" & _
prepareSQL(Request.Form("Zip")) & "', '" & _
prepareSQL(Request.Form("Country")) & "', '" & _
prepareSQL(Request.Form("Phone")) & "', '" & _
prepareSQL(Request.Form("Phone_Extension")) & "', '" & _
prepareSQL(Request.Form("Fax")) & "', '" & _
prepareSQL(Request.Form("Company")) & "', '" & _
prepareSQL(Request.Form("Pay_To")) & "', '" & _
prepareSQL(Request.Form("Tax_ID")) & "', '" & _
prepareSQL(Request.Form("Tax_ID_Type")) & "', '" & _
prepareSQL(Request.Form("Tax_Class")) & "', " & _
Affiliate_ID & "," & _
Request.Form("ID") & "," & _
Request.Form("Approved")
Set objConnection = openConnectionAdmin()
Set objRecordset = openRecordset(strSQL, objConnection)
If objRecordset("Error") = "1" Then
Response.Write objRecordset("Data")
Response.End
End If
objRecordset.Close
Set objRecordset = Nothing
Set objConnection = Nothing
Response.Redirect ( "/admin/users/affiliates/" ) %>
Function openRecordSet(ByVal strSQL, ByRef objConnection)
On Error Resume Next
' logSQL(strSQL)
Set openRecordset = objConnection.Execute(strSQL)
If err.Number <> 0 Then
'Response.Write Err.Number & " - " & Err.Description logError("ASP: openRecordset: " & Err.Number & " - " & Err.Description & ": " & strSQL)
' Call displayErrorPage()
End If
End Function
The error typically is caused by using Set to indicate assignment of an object to a variable, but having a non-object for the right value:
>> Set v = New RegExp
>> [no news here are good news]
>> Set v = "a"
>>
Error Number: 424
Error Description: Object required
So check your openRecordset function. Does it return a recordset by executing
Set openRecordset = ....
(mark the Set) for the given parameters?
Update wrt comments:
This test script:
Option Explicit
' How to test the type of a function's return value that should
' be an object but sometimes isn't. You can't assign the return value
' to a variable because of VBScript's disgusting "Set".
WScript.Echo "TypeName(openConnectionAdmin()): ", TypeName(openConnectionAdmin())
WScript.Echo "TypeName(openRecordset(...)) : ", TypeName(openRecordset("", objConnection))
' Trying to create a connection and a recordset
Dim objConnection : Set objConnection = openConnectionAdmin()
Dim objRecordset : Set objRecordset = openRecordset("", objConnection)
Function openConnectionAdmin()
' Set openConnectionAdmin = CreateObject("ADODB.CONNECTION")
Set openConnectionAdmin = Nothing
End Function
' After removing the comments: Obviously this is a function that
' hides all errors; the programmer should be fed to the lions.
Function openRecordSet(ByVal strSQL, ByRef objConnection)
On Error Resume Next
Set openRecordset = objConnection.Execute(strSQL)
End Function
output:
TypeName(openConnectionAdmin()): Connection
TypeName(openRecordset(...)) : Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'
or
TypeName(openConnectionAdmin()): Nothing
TypeName(openRecordset(...)) : Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'
shows: By hiding every conceivable error in openRecordset() the function can return Empty (undetected!), which isn't an object and can't be assigned to a variable by using Set.
From This question, its answer is almost my answer. But I am facing some sql query issue, I have the following statement in VB
Dim results As DataRow() = table.Select("A = 'foo' AND B = 'bar' AND C = 'baz'")
I want to place foo, bar and baz in variables and use that variables in above statements.
Dim Varfoo As String = "foo"
Dim Varbar As String = "bar"
Dim Varbaz As String = "baz"
I managed to get one variable in statement as
Dim results As DataRow() = table.Select("A = " + Varfoo)
But how to insert multiple sort expressions with variables?
Edit: I got it solved with the answer of vikas as following;
Dim results As DataRow() = table.Select("A = '" & Varfoo & "' And B = '" & Varbar & "' And C = '" & Varbaz & "'")
Have you tried
Dim results As DataRow() = table.Select("A = '" & Varfoo & "'")
Edited
For OR operation
Dim results As DataRow() = table.Select("A = '" & Varfoo & "' OR B = '" & Varbar & "' OR C = '" & Varbaz & "'")
For AND operation
Dim results As DataRow() = table.Select("A = '" & Varfoo & "' AND B = '" & Varbar & "' AND C = '" & Varbaz & "'")
I have a vb6 project and i need to update a visual foxpro table from a recordset.My issue is when i try to update the table i get error msg:Command contains unregnized phrase/keywords.My problem is situated where the date field is concern.I dont know if i written the last portion of the code right.Here is my code:
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & "where code = '" & rs1.Fields("emp_code") & "and transac.date = & trans.txtend &", cn1, adOpenDynamic, adLockPessimistic
Try this:
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & " where code = '" & rs1.Fields("emp_code") & "' and transac.date = '" & trans.txtend &"'", cn1, adOpenDynamic, adLockPessimistic
It looks like you were missing a space before the WHERE keyword and you missed a single-quote after emp_code. It also looks like you had a problem with transac date.
If the solution from G Mastros is still not complete, it may be due to incorrect data type of a "Date" field. you may need to change to
transac.date = CTOD('" & trans.txtend &"') "
as if you are sending in a text string, but the date is of a DATE type field, you'll need to have it converted to a VFP recognized function... CTOD() is Convert Character String to a Date.