I have created a class that will manage connection and commands, I named it DbConfiguration and it uses a Singleton pattern(using dbc as an object name).
My problem is this SQL syntax throws an error when I try to run ExecuteNonQuery()
Using this connection string:
"Provider=Microsoft.ACE.OLEDB.12.0;dbms.accdb;Persist Security Info=False"
I executed this first:
dbc.SetCommand("INSERT INTO inventory ([CallNumber], [Title], [ImageLocation]) VALUES (#CALLNUMBER, #TITLE, #IMAGELOC);");
dbc.GetCommand().Parameters.Add("#CALLNUMBER", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("#TITLE", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("#IMAGELOC", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters["#CALLNUMBER"].Value = txtCallNumber.Text;
dbc.GetCommand().Parameters["#TITLE"].Value = txtTitle.Text;
dbc.GetCommand().Parameters["#IMAGELOC"].Value = (!moveto.Equals("db_storage\\") ? moveto : "db_storage\\no_img.png");
and followed by:
dbc.GetCommand().ExecuteNonQuery();
Next is I executed this code:
dbc.SetCommand("INSERT INTO publishing_info ([ID], [Author], [DateTime], [Publisher], [Pages], [ISBN_NO]) " +
"VALUES (" +
"SELECT([ID] FROM inventory " +
"WHERE inventory.CallNumber=#CALLNUMBER AND inventory.Title=#TITLE AND inventory.ImageLocation=#IMAGELOC), " +
"#AUTHOR, #DATETIME, #PUBLISHER, #PAGES, #ISBN);");
and also followed by:
dbc.GetCommand().ExecuteNonQuery();
Here are the parameters that I have used for your reference:
dbc.GetCommand().Parameters.Add("#AUTHOR", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("#DATETIME", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("#PUBLISHER", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("#PAGES", System.Data.OleDb.OleDbType.UnsignedInt, 4);
dbc.GetCommand().Parameters.Add("#ISBN", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters["#AUTHOR"].Value = txtAuthor.Text;
dbc.GetCommand().Parameters["#DATETIME"].Value = txtYear.Text;
dbc.GetCommand().Parameters["#PUBLISHER"].Value = txtPublisher.Text;
dbc.GetCommand().Parameters["#PAGES"].Value = uint.Parse(txtPages.Text);
dbc.GetCommand().Parameters["#ISBN"].Value = txtISBN.Text;
Here is the screenshot of my stack trace(I can't attach it because I only have 1 rep points)
http://i44.tinypic.com/2w49t84.png
What should I do to make the syntax work?
And also do I need to close the connection first before executing another query?
Update 1
I used DMax(\"[ID]\", \"inventory\") to retrieve the last ID but it returns all the fields of inventory and writes it all on the fields that it can be written to, in my C# code but if I write the query on MS Access 2010 it doesn't do what it does on a C# code. What seems to be the problem?
Update 2
Problem solved with dbc.GetCommand().Parameters.Clear()
You do not need to close the connection, but you do need to insert a left parenthesis in your sub-select:
dbc.SetCommand("INSERT INTO publishing_info ([ID], [Author], [DateTime], [Publisher], [Pages], [ISBN_NO]) " +
"VALUES (" +
"(SELECT([ID] FROM inventory " +
"WHERE inventory.CallNumber=#CALLNUMBER AND inventory.Title=#TITLE AND inventory.ImageLocation=#IMAGELOC), " +
"#AUTHOR, #DATETIME, #PUBLISHER, #PAGES, #ISBN);");
Related
I am creating a message inside a string using a Script task
The code would look like this:
Message = Description +"\n" + Message;
The idea is to receive a message like this:
Description
Description
and so on
Within a messagebox I can see this result, but when I open the mail, the message is composed of one single line:
Description1 Description2
I have also changed "\n" for "\n\r", Environment.NewLine. But it didn't work.
Could you explain me what am I doing wrong?
You need to typecast it as below:
(DT_STR,2,1252)"\r\n"
For example...the below expression in Execute SQL task is dynamic SQL
"INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( " + "'EMPLOYEE_MASTER', " + (DT_STR, 10, 1252) (#[User::EMP_MAST_COUNT])+" );" + (DT_STR,2,1252)"\r\n" + "GO " + (DT_STR,2,1252)"\r\n" + "INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( " + "'DEPT_MASTER', " + (DT_STR, 10, 1252) (#[User::DEPT_MAST_COUNT])+" );" + (DT_STR,2,1252)"\r\n"+ "GO "
And will give output as below...
INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( 'EMPLOYEE_MASTER', 2514);
GO
INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( 'DEPT_MASTER', 2541);
GO
Try "\n\n" . This works but adds an extra line break. In most cases it is adequate.
During a Value-Change inside a browse, my string value suddenly changes, specifically the string(9) will change to string(0).
sample:
in my combo-box, i used a list-item-pair with following code:
cb-name:LIST-ITEM-PAIRS = ?.
cb-name:DELIMITER = '?'.
FOR EACH employee WHERE employee.date-resigned = ? NO-LOCK BY employee.employee-no.
cb-name:ADD-LAST(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + ".",employee.employee-no).
END.
cb-name:SCREEN-VALUE = cb-name:ENTRY(1).
in the value-changed of browse:
ASSIGN cb-name:SCREEN-VALUE =
STRING(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + "." ,
STRING(employee.employee-no, '99999999')).
if the employee no has a string value of 9, progress will change it to 0.. producing an error message that has an invalid value..
ex: from 819001 /*correct*/ to 810001 /*incorrect*/
if there is no string(9), it will display like:818002
if i message the STRING(employee.employee-no, '99999999')), it will display the correct string value
Version doesn't matter in this case, apparently. I just simulated it in 10.2B08 using a temp-table with the named tables. The problem is when you're assigning the screen-value to the combo you're trying to convert the whole string (employee-no + names + separators) into format 99999999.
Since your combo is list-item-pairs
('Whatever I want it to display','the real value',
'and so on display' , 'and so forth value')
your solution is to assign the screen value just to the real value, disregard the label. In other words, as simple as changing your value-changed code to
ASSIGN cb-name:SCREEN-VALUE = STRING(employee.employee-no, '99999999') .
It worked for me. Let me know if you are still having trouble with it.
This is a more explicite extension on my previous question.
From an button on an XPage I create a new database
targetDB = dir.createDatabase(fileName);
I then copy a bunch of stuff into the targetDB from the sourceDB. I then want to set the launch properties in the targetDB which is where the problem comes.
I know that I can get the iconNote = targetDB.getDocumentByID("FFFF0010") except there is no iconDoc in the target. Does anyone have a way to create this doc with the specific NoteID?
I tried copying the iconNote document from the sourceDB to the targetDB but that does not work. Changes the UNID and noteID. Can't find any database method to create an icon Note.
Found lots of stuff on how to change the settings in the iconNote, but nothing on how to create one if there is not one in the database.
Thanks to Jesse I took his code and changed it to SSJS and it works fine.
var dir:NotesDbDirectory = session.getDbDirectory("Development");
var newDB:NotesDatabase = dir.createDatabase("XPages/install/created.nsf");
var importer:NotesDxlImporter = session.createDxlImporter();
importer.setDesignImportOption(6);
var dxl:String = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Test Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
var iconNote = newDB.getDocumentByID("FFFF0010");
iconNote.replaceItemValue("$DefaultXPage", "xpWFSDemo.xsp");
iconNote.replaceItemValue("$DefaultClientXPage", "xpWFSDemo.xsp");
iconNote.save();
dBar.info(iconNote.getItemValueString("$Flags"));
Something like this oughta do it:
DbDirectory dir = session.getDbDirectory(null);
Database newDB = dir.createDatabase("tests/created.nsf");
DxlImporter importer = session.createDxlImporter();
importer.setDesignImportOption(DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE);
String dxl = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Some DB Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
That's with the two "open XPage" options set already - you could also include the two XPage name items the same way, and it may be a good idea to export the icon note from an existing DB (database.getDocumentByID("FFFF0010").generateXML()) and paste in the actual icon item as well, since this DXL will result in an icon-less database. Nonetheless, it seems to work in my testing as a basis.
And after that point, you'll be able to fetch the icon note using the usual "FFFF0010" pseudo-ID and replace item values the same way I mentioned before.
I'm trying to solve an issue I have when I'm trying to use OLE DB for reading Excel files.
I found that the problem is because there is a hash mark (#) in the sheet name.
Unfortunately, I can't rename the sheet.
So after some tries, I've succeeded to read a full sheet by adding quotation marks ('):
Before
Select * from [" + sheetName + "$];
After (working)
Select * from ['" + sheetName + "$'];
But then I got stuck when trying to read a range from the sheet with the OLE DB feature:
Select * from [" + sheetName + "$" + fromCell + ":" + toCell + "];
When I try to send this command, it's seems like the # is replaced by . and then it cannot find the sheet.
I've tried many combination and escape codes and didn't find any solution. How can I access this file?
Your final output should look like this
'MySheet$A1:B2'
So your select should be
var SheetName = "MySheet";
var fromCell = "A1";
var toCell = "B2";
var sql = "Select * from ['" + SheetName + "$" + fromCell + ":" + toCell + "']";
Console.WriteLine(sql);
// Output
// Select * from ['MySheet$A1:B2']
Also consider parametrising your sql for better readability and also preventing sql code injection. You can find a guide for how to do it at OleDbCommand.Parameters.
I have another problem with cassandra.. I have export a table in Mysql in .csv format and import it in Cassandra.the Mysql table contains filds date and time of types Date and Time. I define these fields as varchar in cassandra. so when I import the .csv file and execute the below query, it shows me an error:
my query:
ResultSet rs = stmnt.ExecuteQuery("Select * from station info where IDstation = 1011 and IDinfo = 18412:);
while (rs.next) {
System.out.println(rs1.getFloate(1) + " " +
rs1.getString(2) + " " +
rs1.getFloate(3) + " " +
rs1.getString(4) + " " +
rs1.getInt(5) + " " +
rs1.getInt(6) + " " +
rs1.getString(7) + " " +
rs1.getFloate(8));
}
the 7th field in print command is date..
and the error is:
java.lang.NumberFormatException: For input String: "6/2/1962"
at org.apache.cassandracql.jdbc.cassandraResultSet.getInt(CassandraResultSet.java:619)
at org.apache.cassandracql.jdbc.cassandraResultSet.getInt(CassandraResultSet.java:590)
I can not understand what it says... can anyone help me please?
Read what the stacktrace is telling you carefully
java.lang.NumberFormatException: For input String: "6/2/1962"
at org.apache.cassandracql.jdbc.cassandraResultSet.getInt(CassandraResultSet.java:619)
at org.apache.cassandracql.jdbc.cassandraResultSet.getInt(CassandraResultSet.java:590)
The error you are getting is to do with an attempt to retrieve a string as a integer.
Make sure that the date column is coming at 7th position only and not anywhere else. I suggest you to improve your query by specifying the column names. For eg.,
SELECT Col1, Col2... FROM Table
This avoids confusion of column order.