|
query is:
INSERT INTO FileInfo VALUES ('2021', 'ALex', 'Dunlop') WHERE NOT EXISTS (SELECT 1 FROM FileInfo WHERE EqpCode='2021')
The table has 3 columns.
SQLite says:
syntax error near WHERE
How can I fix it?
modified 8-Jul-21 13:40pm.
|
|
|
|
|
First off, don't INSERT like that - always list the columns into which you want to ISNERT values - if someone (very sensibly) adds an ID column for example, it can really mess up your code, even if the ID column is of IDENTITY type so you can't INSERT to it!
Listing the columns in the order you supply their values makes your code safer and easier to maintain in future.
Secondly, you can't add a WHERE clause to an INSERT operation because it doesn't affect any existing rows - it only ever adds new ones.
If you want to do an insert if no matching rows exist use IF[^] or CASE[^] instead.
I'd probably use COUNT(...) = 0 instead of EXISTS(...) as well.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Do you mean this:
INSERT INTO FileInfo (EqpCode, EqpName, FileName) VALUES ('123', 'rty', 'iuo') WHERE NOT EXISTS (SELECT 1 FROM FileInfo IF EqpCode='123')
It has the same Error.
|
|
|
|
|
Again, there is no such thing as a WHERE clause on an INSERT statement. Remove everything from WHERE to the end of the statement.
|
|
|
|
|
I had used a similar query in C# and it was working well (SQL server CE):
mycommand.CommandText = $"INSERT INTO MyData([Wo], [EqN], [Code], [Work], [Cost]) SELECT '{DataGridView3.Rows[i].Cells[0].Value}', '{DataGridView3.Rows[i].Cells[1].Value}', '{DataGridView3.Rows[i].Cells[2].Value}', '{DataGridView3.Rows[i].Cells[3].Value}', '{DataGridView3.Rows[i].Cells[4].Value}' WHERE NOT EXISTS (SELECT 1 FROM MyData WHERE [Wo]='{DataGridView3.Rows[i].Cells[0].Value}' AND [Code]='{DataGridView3.Rows[i].Cells[2].Value}')";
|
|
|
|
|
Yes, but the WHERE clause is connected to the SELECT , not the INSERT .
|
|
|
|
|
I found an easy way. I changed EqpCode column type to UNIQUE and Unique Conflict Clause to REPLACE.
Then:
INSERT INTO FileInfo(EqpCode, EqpName, FileName) VALUES ('123', 'test01', 'test02')
ON CONFLICT(EqpCode) DO UPDATE
SET EqpName = EXCLUDED.EqpName,
FileName = EXCLUDED.FileName;
modified 8-Jul-21 15:04pm.
|
|
|
|
|
Some have given you the answer but not really shown you what they mean. You can't use WHERE without a SELECT. So, you do something like this:
INSERT INTO Table1(Field1, Field2, ...)
SELECT '2021', 'Alex', ...
WHERE NOT EXISTS (...)
|
|
|
|
|
DevParty wrote: You can't use WHERE without a SELECT.
Um ... you sure?
UPDATE MyTable SET MyColumn = @MyValue WHERE MyOtherColumn = @MyOtherValue
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: DevParty wrote: You can't use WHERE without a SELECT.
Um ... you sure?
UPDATE MyTable SET MyColumn = @MyValue WHERE MyOtherColumn = @MyOtherValue
I'm pretty sure he meant an INSERT, clause, not an UPDATE one! 
|
|
|
|
|
What he may have meant and what he said are not necessarily the same thing!
Particularly with beginners, you have to be accurate - a bald statement like "WHERE only works with SELECT" is not accurate and can confuse.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: a bald statement like "WHERE only works with SELECT" is not accurate and can confuse.
Would that be a statement without any hair?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Wouldn't know - I still have a ponytail.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
For inserting data. Stay in context. 
|
|
|
|
|
I want to create shared memory in a C# windows application. And a second console application in visual studio has to share the same memory using OpenFileMapping function.
Is it possible to share memory as I mentioned between one application in C# and other application in Visual C++ console application.
Please advise and suggest the ways of doing this
|
|
|
|
|
The BCL has plenty of support for memory-mapped files:
Memory-Mapped Files | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This gives details for creating and opening shared memory between 2 C# application processes.
Please help me to share memory between 2 applications, one in C# and other VC++ console application to open the share memory created in C# application. Is it possible of doing this? Please advise
|
|
|
|
|
The documentation tells you how to create or access memory-mapped files from a C# application.
You presumably already know how to create or access memory-mapped files from a C++ application. If not, the Microsoft docs site has details:
Memory-Mapped File Information - Win32 apps | Microsoft Docs[^]
The file doesn't care which language was used to create the process that's accessing it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I would strongly suggest that you don't: instead redesign to use message based communications via Named Pipes[^] or Sockets C#[^] / Sockets C++[^]
It's a much more robust solution that can be a whole load more flexible.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Going in circles.
Shared memory - C# Discussion Boards
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
But I didnt get a solution.
Please provide me some details and hints how to share memory between C# application and VC++ console application
|
|
|
|
|
You're stuck on one approach and not open to suggestions.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If helps.
A memory mapped file is an OS supported option.
C++ can use and access a memory mapped file.
C# can use and access a memory mapped file.
So the solution is
1. Study memory mapped files so you specifically understand how they can be shared between applications. I believe sharing requires a specific set up.
2. Study the api for C++ memory mapped files.
3. Study the api for C# memory mapped files.
4. Design how the memory mapped file will be used. Pay attention to failure scenarios.
5. Use 2 and 4 to implement a solution in the C++ app.
6. Use 3 and 4 to implement a solution in the C# app.
|
|
|
|
|
Hi,
I searched DevExpress forum. They say that I need to use gridView.GetRowCellValue() method.
I used this code:
private void gridView4_DoubleClick(object sender, EventArgs e)
{
DXMouseEventArgs mouseEvent = e as DXMouseEventArgs;
GridView view = sender as GridView;
GridHitInfo info = view.CalcHitInfo(mouseEvent.Location);
if (info.InRow || info.InRowCell)
{
MessageBox.Show(gridView4.GetRowCellValue(info.RowHandle, "File Name").ToString());
}
}
But I have error in MessageBox.... line.
it says:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
DevExpress.XtraGrid.Views.Base.ColumnView.GetRowCellValue(...) returned null.
|
|
|
|
|
Either your RowHandle or column name is invalid. Use the debugger to find out which, and why.
|
|
|
|