Why Identifier Expected? - mysql

hi can you please help me what is missing or problem with my script? i keep on getting compiling error: Identifier Expected. It is in the character ".[i"
myRange.Value2 = GridView1.[i,j].Value + ";" == null ? "" : GridView1.[i,j].Text + ";";

It will be:
myRange.Value2 = GridView1.Rows[i].Cells[j].Text+ ";" == null ? "" : GridView1.Rows[i].Cells[j].Text + ";";
GridView.Rows[i].Cells[j]
where i = row index and
j = cell index

First, you have a typo: there is a dot after GridView1, which isn't allowed since it expects an identifier then (as the message says). GridView1.Rows would have been valid for example.
Another problem is that your logic is wrong.
This code will never yield true, since ";" is not null:
GridView1[i, j].Value + ";" == null
I think you should drop the + ";".

Related

extracting multiple values from JSON

In Node.js 6.10, an API call returns JSON string:
in C# code is return "{\"response\" : \" " + responseMsg + " \" , \"isNewActiveDirectoryUser\" : \" " + isNewActiveDUser + " \"}";
this returns
"\"{\\\"response\\\" : \\\" Not latest version of file, update not performed \\\" , \\\"isNewActiveDirectoryUser\\\" : \\\" False \\\"}\""
I want to extract response & isNewActiveDirectoryUser and place the result in variables.
I have tried
context.done(null, body);
var jsonBody = JSON.parse(body);
let valueReturned1 = jsonBody.response; //have tried this
let valueReturned2 =jsonBody["response"]; //and this
both display undefined.
What am I doing wrong?
I can console.log the body and it is populated
Your json is double stringified.
JSON.parse(JSON.parse("\"{\\\"response\\\" : \\\" Not latest version of file, update not performed \\\" , \\\"isNewActiveDirectoryUser\\\" : \\\" False \\\"}\"")).response === " Not latest version of file, update not performed "
Sounds like you need to fix it on the C# side

Completed 500 Internal Server Error in Ruby on Rails

I'm trying to do a search but did not get any result. This is wrong:
def BuscarRoles(usuario)
#sql="SELECT * FROM rols WHERE id_rol IN (SELECT id_rol FROM rol_usuarios WHERE id_usuario = "+usuario.to_s+")"
#roles = ActiveRecord::Base.connection.execute(#sql)
#tira='['
if #roles.count>0
#aroles.each do |rol|
#tira = #tira+" { id_rol: '" + rol.id_rol.to_s + "', descripcion: '" + rol.descripcion.to_s
j=j+1
if j<#roles.count
#tira = #tira+ " }, "
else
#tira = #tira+" } ] "
end
end
else
#tira= #tira+"{ { text: 'No hay datos', id: '0', href: '', leaf: true } } ]"
end
return #tira
end
By just looking at the code, with no trace given, I can only see one thing that might cause the error.
ActiveRecord::Base.connection.execute
#the result of the above code is Mysql2::Result of course depending on what database you're using.
Hence you can't use .(dot) operator on the result as you would do on a model object.
So you could make the following changes in the code
#aroles.each do |rol|
#puts rol.id_role => this will throw error
puts rol[0] # this should work assuming id_role is the first column
end
That should help. As you mentioned in the comment that your getting error in #aroles.each do |rol| then you must check if the sql statement is returning you any results at all ?
BTW, even if the query doesn't return any results, it would simply return an empty array and iterating an empty array would simple give nothing but not throw any error.
So to conclude
Check if any records are returned at all
Use index instead of the column name as they are active_record objects
Hope that helps.

SQL injection using the value of a parameter as its name

Am I vulnerable to sql injection if I use the the value of parameter as its name?
for(String tag : choixalerte.selectedNomExestingtags)
where += " ach.NOM_ACHTEUR LIKE :" + tag + " or ao.OBJET LIKE :" + tag + " or lot.INTITULE LIKE :" + tag + "";
// ...
Query native_query = entityManager.createNativeQuery(...);
if(choixalerte.selectedNomExestingtags != null)
for(String tag : choixalerte.selectedNomExestingtags)
native_query.setParameter(tag, "%" + tag + "%");
Yes. You should not concatenate string in a query.
If you do not want to suffer attack you have some options:
1) Do not concatenate, use "?" instead
2) Sanitize your parameters, you could remove all invalid characters. Remove like # or -- and any other kind of sql commands.
Be aware that you will need to always take a good care in this code because, if a new kind of attack appears you will need to edit the sanitize code.

Undefined method 'join' during mysql action (ruby/sinatra)

Undefined method 'join' during mysql action (ruby/sinatra)
Code:
rs = con.query('select * from userlog')
#logentry = ""
rs.each_hash { |h|
#logentry = #logentry + "ID: " + h['Id'] + "User: " + h['user'] + " - Time: " + h['datetime'] + " - Description: " + h['description'] + "<br>"
}
Error:
undefined method `join' for #<String:0x007f70585b68f8>
when I add ".to_s" to the "h[Id]" then I get blank results for the ID but the rest is shown.
It sounds like your 'userlog' table column name for the identifier is not 'Id', maybe 'id'. Otherwise it would have been selected normally.
I had similar problem. The reason was that table name was incorrect in database, and for some reason MySQL error messages were incorrect. Check all database, table and variable names.

How can you check for null in a VBA DAO record set?

I have an optional field in a database that I'm pulling out using a DAO Record Set. I need to check whether or not the field is set before I concatenate it with other fields. So far I have the following code snippet which I've tried with both Is and = (that's the obviously wrong syntax [[Is | =]]) to no avail. It appears that if I use = it will not correctly compare with Null and if I use Is then it complains that it's not comparing with an Object.
While Not rs.EOF
If rs.Fields("MiddleInitial") [[Is | =]] Null Then thisMiddleInitial = "" Else thisMiddleInitial = rs.Fields("MiddleInitial")
If prettyName(myLastName, myFirstName, myMiddleInitial) = prettyName(rs.Fields("LastName"), rs.Fields("FirstName"), thisMiddleInitial) Then
MsgBox "Yay!"
End If
rs.MoveNext
Wend
If there's a simpler way to do this I'm totally open to it. prettyName takes 3 Strings as parameters and initially I was just trying to pass rs.Fields("MiddleName") directly but it threw up at a Null value. I'd prefer to do something more direct like that but this is the best I could come up with.
How about:
IsNull(rs.Fields("MiddleInitial").Value)
You could also have a look at this article which has some explanation about Null values in Access VBA apps and how to handle them.
For the example you show, Nz would work:
thisMiddleInitial = Nz(rs!MiddleInitial,"")
Or simply concatenating the string with an empty string:
thisMiddleInitial = rs!MiddleInitial & ""
Your question has been answered by Remou, seems to me, but it occurs to me that you may just be trying to get proper concatenation of the name fields. In that case, you could use Mid() and Null propagation in VBA to get the result.
I don't use separate middle initial fields, so my usual name concatenation formula is:
Mid(("12" + LastName) & (", " + FirstName), 3)
The "12" string at the beginning is going to be tossed away if LastName is Not Null and ignored if it is null, because the + concatenation operator propagates Nulls.
To extend this to include middle intials would look like this:
Mid(("12" + LastName) & (", " + FirstName) & (" " + MiddleInitial), 3)
Assuming your UDF is not doing some kind of complicated cleanup of nicknames/abbreviations/etc., this could replace it entirely, seems to me.
If rst.Fields("MiddleInitial").Value = "Null" Then
This works for me. I use MS SQL Database.
I think the NoMatch option might work in this situation:
If rs.NoMatch = True Then
I prefer using the below to account for both Null and Empty string values. It's a good check to use you have forms collecting values from users.
If Trim(rs.Fields("MiddleInitial") & "") = "" then