Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-24-2020 04:55 AM
Hi together,
I try to save a value with a Cypher Query and Nei4j v4 and Neo4j.Driver in C#
My problem is that the value of my variable contains a singlequote, for example like:
ÖöÜüÄäßµ@€-&'.Sb34
Thats my Query:
var Name = "ÖöÜüÄäßµ@€-&'.Sb34";
var query2Neo = ("CREATE (p:Person { Name:'" + Name + "'})");
Are there another Way to avoid those kind of problems?
Best regards
Solved! Go to Solution.
02-24-2020 05:37 AM
Hi @CodeCase
You don't have to use string building - read cypher manual:
https://neo4j.com/docs/cypher-manual/4.0/syntax/parameters/
CREATE (n:Person { name: $name })
02-24-2020 05:37 AM
Hi @CodeCase
You don't have to use string building - read cypher manual:
https://neo4j.com/docs/cypher-manual/4.0/syntax/parameters/
CREATE (n:Person { name: $name })
02-24-2020 06:43 AM
Hi @paul.are,
thanks for your reply.
I need to use Neo4j.Driver v4 with the following Syntax
IDriver driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "neo4j"));
IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));
var name = "ÖöÜüÄäßµ@€-&'.Sonderbör";
var query2Neo = ("CREATE (p:Person {name: $name})", new { name });
IResultCursor cursor = await session.RunAsync(query2Neo.ToString());
await cursor.ConsumeAsync().ConfigureAwait(true);
await session.CloseAsync();
await driver.CloseAsync();
dont know if thats the "best" approach for using the .Net Driver in neo4j. However its not working.neo4j
I get the following Error:
EXCEPTION: Neo4j.Driver.ClientException: Invalid input '(': expected (line 1, column 1 (offset: 0))
"(CREATE (p:Person {name: $name}), { name = ÖöÜüÄäßµ@€-&'.Sonderbör })"
^
at Neo4j.Driver.Internal.MessageHandling.ResponsePipelineError.EnsureThrownIf(Func`2 predicate)
02-24-2020 10:32 AM
Try this -
var name = "ÖöÜüÄäßµ@€-&'.Sonderbör";*
var query2Neo = "CREATE (p:Person {Name: $name})";
IResultCursor cursor = await session.RunAsync(query2Neo.ToString() , new { name });
Before this you need to create a param object for this to work.
I have tried with a java equivalent code and it works. - use only related part
Map<String, Object> parameters = new HashMap<String, Object>();
String name = "ÖöÜüÄäßµ@€-&'.Sonderbör";
String query2Neo = "CREATE (p:Person {Name: $name})";
parameters.put("name", name);
session.run(query2Neo, parameters);
Please follow this and if you still get the issue, please let me know
02-25-2020 07:39 AM
02-24-2020 06:45 AM
02-25-2020 12:18 PM
Thanks , Happy to help!
All the sessions of the conference are now available online