Please i need your help, desperately.
I want to update (periodically) a SQL Server database from inside Nav. I am using ADO to make the connection with success. However, i cant send a query to SQL Server using a C/SIDE variable. Below are the variables i used
Name DataType Subtype Lenght
Cust Record Customer
CustName Text 50
CODE:
WITH Cust DO BEGIN
IF Cust.FIND('-') THEN BEGIN
REPEAT
CustName := Cust."Account Name";
SQLString := 'insert into testdata(texttest) values(''+CustName+'')';
ADORecSet := ADOConnection.Execute(SQLString);
UNTIL Cust.NEXT = 0;
END;
END;
When i run the codeunit, it iterates through the C/SIDE table as it should, but inserts +CustName+ into the SQL Server table as the name of every of the customers, instead of substituting the variable with the values its supposed to hold. When i use single quotes and the plus sign like this '+CustName+', it picks the first name of the first customer (Mark, the complete name there is Mark Melton) and throws this exception "The Name Mark is not permitted in this context, only constants, expressions or variables are allowed here.
Please what do i need to do? Waiting eagerly.
Melton
Answers
Check also, if you not fill all fields in the table, if the fields on the sqldatabase allowes NULL values.
Regards
"The call to member Execute failed. Microsoft OLE DB Provider for SQL Server returned the following message: The name 'Mark' is not permited in this context. Only constants, expressions, or variables allowed here. Column names are not permitted"
Looks like its SQL server that is rejecting the value sent to it. Could it be a problem of type conversion? The first name on the Customer table is Mark Melton, a text field, of Lenght 50. The corresponding SQL field i am trying to inject into is a varchar, 100. What is wrong here?
Please help me out. Grrrrr :bug:
Waiting actively, anticipating...
Can u run the copied command directly in the query analizer?
This is the command i ran in SQL Query Analyzer: insert into testdata (texttest) values ('Mark Melton').
So help me God! What is wrong?
Group Program Manager, Client
Microsoft Dynamics NAV
http://blogs.msdn.com/freddyk
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
It worked! It did! I will post a full procedure for other later. Thanks alot! Thank you BBrown and Garak too. You all helped! Now i will not get fired by my customer! Bingo!
Mark!
1) Can you give a good title to your topic, so that it is possible for someone else, who has the same problem, to find your topic.
2) Can you also change the attribute of the topic to Solved.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Blessings...